Adds a function to convert TCP flags into a string
This commit is contained in:
@@ -51,6 +51,31 @@ TcpHeader::~TcpHeader ()
|
||||
{
|
||||
}
|
||||
|
||||
std::string
|
||||
TcpHeader::FlagsToString(const uint8_t& flags, const std::string& delimiter)
|
||||
{
|
||||
static const char* flagNames[8] = {
|
||||
"FIN",
|
||||
"SYN",
|
||||
"RST",
|
||||
"PSH",
|
||||
"ACK",
|
||||
"URG",
|
||||
"ECE",
|
||||
"CWR"
|
||||
};
|
||||
std::string flagsDescription = "";
|
||||
for(int i = 0; i < 8; ++i)
|
||||
{
|
||||
if( flags & (1 << i) )
|
||||
{
|
||||
if(flagsDescription.length() > 0) flagsDescription += delimiter;
|
||||
flagsDescription.append(flagNames[i]);
|
||||
}
|
||||
}
|
||||
return flagsDescription;
|
||||
}
|
||||
|
||||
void
|
||||
TcpHeader::EnableChecksums (void)
|
||||
{
|
||||
@@ -250,41 +275,7 @@ TcpHeader::Print (std::ostream &os) const
|
||||
|
||||
if (m_flags != 0)
|
||||
{
|
||||
os<<" [";
|
||||
if ((m_flags & FIN) != 0)
|
||||
{
|
||||
os<<" FIN ";
|
||||
}
|
||||
if ((m_flags & SYN) != 0)
|
||||
{
|
||||
os<<" SYN ";
|
||||
}
|
||||
if ((m_flags & RST) != 0)
|
||||
{
|
||||
os<<" RST ";
|
||||
}
|
||||
if ((m_flags & PSH) != 0)
|
||||
{
|
||||
os<<" PSH ";
|
||||
}
|
||||
if ((m_flags & ACK) != 0)
|
||||
{
|
||||
os<<" ACK ";
|
||||
}
|
||||
if ((m_flags & URG) != 0)
|
||||
{
|
||||
os<<" URG ";
|
||||
}
|
||||
if ((m_flags & ECE) != 0)
|
||||
{
|
||||
os<<" ECE ";
|
||||
}
|
||||
if ((m_flags & CWR) != 0)
|
||||
{
|
||||
os<<" CWR ";
|
||||
}
|
||||
|
||||
os<<"]";
|
||||
os<<" [" << FlagsToString(m_flags) <<"]";
|
||||
}
|
||||
|
||||
os<<" Seq="<<m_sequenceNumber<<" Ack="<<m_ackNumber<<" Win="<<m_windowSize;
|
||||
|
||||
@@ -41,12 +41,22 @@ namespace ns3 {
|
||||
* as methods for serialization to and deserialization from a byte buffer.
|
||||
*/
|
||||
|
||||
class TcpHeader : public Header
|
||||
class TcpHeader : public Header
|
||||
{
|
||||
public:
|
||||
TcpHeader ();
|
||||
virtual ~TcpHeader ();
|
||||
|
||||
/**
|
||||
* \brief Converts an integer into a human readable list of Tcp flags
|
||||
*
|
||||
* \param flags List of TCP flags to convert to a readable string
|
||||
* \param delimiter String to insert between flags
|
||||
*
|
||||
* \return the generated string
|
||||
**/
|
||||
static std::string FlagsToString(const uint8_t& flags, const std::string& delimiter="|");
|
||||
|
||||
/**
|
||||
* \brief Enable checksum calculation for TCP
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user