Skip to content

Commit

Permalink
Fixed ostream operator<< declared outside the class namespace, preven…
Browse files Browse the repository at this point in the history
…ting ADL. (#1696)
  • Loading branch information
Dimi1010 authored Jan 23, 2025
1 parent 6a49ae5 commit 2d0fc5a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 45 deletions.
11 changes: 5 additions & 6 deletions Packet++/header/Layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,9 @@ namespace pcpp
virtual bool shortenLayer(int offsetInLayer, size_t numOfBytesToShorten);
};

inline std::ostream& operator<<(std::ostream& os, const pcpp::Layer& layer)
{
os << layer.toString();
return os;
}
} // namespace pcpp

inline std::ostream& operator<<(std::ostream& os, const pcpp::Layer& layer)
{
os << layer.toString();
return os;
}
66 changes: 33 additions & 33 deletions Packet++/header/LdapLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1320,47 +1320,47 @@ namespace pcpp
: LdapResponseLayer(std::move(asn1Record), data, dataLen, prevLayer, packet)
{}
};
} // namespace pcpp

inline std::ostream& operator<<(std::ostream& os, const pcpp::LdapControl& control)
{
os << "{" << control.controlType << ", " << control.controlValue << "}";
return os;
}

inline std::ostream& operator<<(std::ostream& os, const pcpp::LdapAttribute& attr)
{
os << "{" << attr.type << ", {";
inline std::ostream& operator<<(std::ostream& os, const pcpp::LdapControl& control)
{
os << "{" << control.controlType << ", " << control.controlValue << "}";
return os;
}

std::string separator;
for (const auto& value : attr.values)
inline std::ostream& operator<<(std::ostream& os, const pcpp::LdapAttribute& attr)
{
os << separator << value;
if (separator.empty())
os << "{" << attr.type << ", {";

std::string separator;
for (const auto& value : attr.values)
{
separator = ", ";
os << separator << value;
if (separator.empty())
{
separator = ", ";
}
}
}

os << "}}";
return os;
}

inline std::ostream& operator<<(std::ostream& os,
const pcpp::LdapBindRequestLayer::SaslAuthentication& saslAuthentication)
{
os << "{" << saslAuthentication.mechanism << ", {";
os << "}}";
return os;
}

std::string separator;
for (const auto& value : saslAuthentication.credentials)
inline std::ostream& operator<<(std::ostream& os,
const pcpp::LdapBindRequestLayer::SaslAuthentication& saslAuthentication)
{
os << separator << "0x" << std::hex << static_cast<int>(value) << std::dec;
if (separator.empty())
os << "{" << saslAuthentication.mechanism << ", {";

std::string separator;
for (const auto& value : saslAuthentication.credentials)
{
separator = ", ";
os << separator << "0x" << std::hex << static_cast<int>(value) << std::dec;
if (separator.empty())
{
separator = ", ";
}
}
}

os << "}}";
return os;
}
os << "}}";
return os;
}
} // namespace pcpp
11 changes: 5 additions & 6 deletions Packet++/header/Packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,9 @@ namespace pcpp
return dynamic_cast<TLayer*>(curLayer);
}

inline std::ostream& operator<<(std::ostream& os, const pcpp::Packet& packet)
{
os << packet.toString();
return os;
}
} // namespace pcpp

inline std::ostream& operator<<(std::ostream& os, const pcpp::Packet& packet)
{
os << packet.toString();
return os;
}

0 comments on commit 2d0fc5a

Please sign in to comment.