Adds a function to convert TCP flags into a string

This commit is contained in:
Matthieu Coudron
2015-05-04 12:31:32 -07:00
parent b34e8c4a0c
commit 02d5a5ef6b
2 changed files with 37 additions and 36 deletions

View File

@@ -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;

View File

@@ -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
*