Skip to content

Commit 2d0fc5a

Browse files
authored
Fixed ostream operator<< declared outside the class namespace, preventing ADL. (#1696)
1 parent 6a49ae5 commit 2d0fc5a

File tree

3 files changed

+43
-45
lines changed

3 files changed

+43
-45
lines changed

Packet++/header/Layer.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,9 @@ namespace pcpp
232232
virtual bool shortenLayer(int offsetInLayer, size_t numOfBytesToShorten);
233233
};
234234

235+
inline std::ostream& operator<<(std::ostream& os, const pcpp::Layer& layer)
236+
{
237+
os << layer.toString();
238+
return os;
239+
}
235240
} // namespace pcpp
236-
237-
inline std::ostream& operator<<(std::ostream& os, const pcpp::Layer& layer)
238-
{
239-
os << layer.toString();
240-
return os;
241-
}

Packet++/header/LdapLayer.h

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,47 +1320,47 @@ namespace pcpp
13201320
: LdapResponseLayer(std::move(asn1Record), data, dataLen, prevLayer, packet)
13211321
{}
13221322
};
1323-
} // namespace pcpp
1324-
1325-
inline std::ostream& operator<<(std::ostream& os, const pcpp::LdapControl& control)
1326-
{
1327-
os << "{" << control.controlType << ", " << control.controlValue << "}";
1328-
return os;
1329-
}
13301323

1331-
inline std::ostream& operator<<(std::ostream& os, const pcpp::LdapAttribute& attr)
1332-
{
1333-
os << "{" << attr.type << ", {";
1324+
inline std::ostream& operator<<(std::ostream& os, const pcpp::LdapControl& control)
1325+
{
1326+
os << "{" << control.controlType << ", " << control.controlValue << "}";
1327+
return os;
1328+
}
13341329

1335-
std::string separator;
1336-
for (const auto& value : attr.values)
1330+
inline std::ostream& operator<<(std::ostream& os, const pcpp::LdapAttribute& attr)
13371331
{
1338-
os << separator << value;
1339-
if (separator.empty())
1332+
os << "{" << attr.type << ", {";
1333+
1334+
std::string separator;
1335+
for (const auto& value : attr.values)
13401336
{
1341-
separator = ", ";
1337+
os << separator << value;
1338+
if (separator.empty())
1339+
{
1340+
separator = ", ";
1341+
}
13421342
}
1343-
}
13441343

1345-
os << "}}";
1346-
return os;
1347-
}
1348-
1349-
inline std::ostream& operator<<(std::ostream& os,
1350-
const pcpp::LdapBindRequestLayer::SaslAuthentication& saslAuthentication)
1351-
{
1352-
os << "{" << saslAuthentication.mechanism << ", {";
1344+
os << "}}";
1345+
return os;
1346+
}
13531347

1354-
std::string separator;
1355-
for (const auto& value : saslAuthentication.credentials)
1348+
inline std::ostream& operator<<(std::ostream& os,
1349+
const pcpp::LdapBindRequestLayer::SaslAuthentication& saslAuthentication)
13561350
{
1357-
os << separator << "0x" << std::hex << static_cast<int>(value) << std::dec;
1358-
if (separator.empty())
1351+
os << "{" << saslAuthentication.mechanism << ", {";
1352+
1353+
std::string separator;
1354+
for (const auto& value : saslAuthentication.credentials)
13591355
{
1360-
separator = ", ";
1356+
os << separator << "0x" << std::hex << static_cast<int>(value) << std::dec;
1357+
if (separator.empty())
1358+
{
1359+
separator = ", ";
1360+
}
13611361
}
1362-
}
13631362

1364-
os << "}}";
1365-
return os;
1366-
}
1363+
os << "}}";
1364+
return os;
1365+
}
1366+
} // namespace pcpp

Packet++/header/Packet.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,9 @@ namespace pcpp
445445
return dynamic_cast<TLayer*>(curLayer);
446446
}
447447

448+
inline std::ostream& operator<<(std::ostream& os, const pcpp::Packet& packet)
449+
{
450+
os << packet.toString();
451+
return os;
452+
}
448453
} // namespace pcpp
449-
450-
inline std::ostream& operator<<(std::ostream& os, const pcpp::Packet& packet)
451-
{
452-
os << packet.toString();
453-
return os;
454-
}

0 commit comments

Comments
 (0)