Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

TCPDumper Class Reference

#include <TCPDump.h>

List of all members.


Detailed Description

Dumps TCP packets in tcpdump format.


Public Member Functions

 TCPDumper (std::ostream &o)
void dump (bool l2r, const char *label, IPDatagram *dgram, const char *comment=NULL)
void dumpIPv6 (bool l2r, const char *label, IPv6Datagram_Base *dgram, const char *comment=NULL)
void dump (bool l2r, const char *label, TCPSegment *tcpseg, const std::string &srcAddr, const std::string &destAddr, const char *comment=NULL)
void dump (const char *label, const char *msg)

Protected Attributes

int seq
std::ostream * outp


Constructor & Destructor Documentation

TCPDumper::TCPDumper std::ostream &  o  ) 
 

00024 {
00025     outp = &out;
00026 }


Member Function Documentation

void TCPDumper::dump const char *  label,
const char *  msg
 

00133 {
00134     std::ostream& out = *outp;
00135 
00136     // seq and time (not part of the tcpdump format)
00137     char buf[30];
00138     sprintf(buf,"[%.3f%s] ", simulation.simTime(), label);
00139     out << buf;
00140 
00141     out << msg << "\n";
00142 }

void TCPDumper::dump bool  l2r,
const char *  label,
TCPSegment tcpseg,
const std::string &  srcAddr,
const std::string &  destAddr,
const char *  comment = NULL
 

00076 {
00077     std::ostream& out = *outp;
00078 
00079     // seq and time (not part of the tcpdump format)
00080     char buf[30];
00081     sprintf(buf,"[%.3f%s] ", simulation.simTime(), label);
00082     out << buf;
00083 
00084     // src/dest
00085     if (l2r)
00086     {
00087         out << srcAddr << "." << tcpseg->srcPort() << " > ";
00088         out << destAddr << "." << tcpseg->destPort() << ": ";
00089     }
00090     else
00091     {
00092         out << destAddr << "." << tcpseg->destPort() << " < ";
00093         out << srcAddr << "." << tcpseg->srcPort() << ": ";
00094     }
00095 
00096     // flags
00097     bool flags = false;
00098     if (tcpseg->synBit()) {flags=true; out << "S";}
00099     if (tcpseg->finBit()) {flags=true; out << "F";}
00100     if (tcpseg->pshBit()) {flags=true; out << "P";}
00101     if (tcpseg->rstBit()) {flags=true; out << "R";}
00102     if (!flags) {out << ".";}
00103     out << " ";
00104 
00105     // data-seqno
00106     if (tcpseg->payloadLength()>0 || tcpseg->synBit())
00107     {
00108         out << tcpseg->sequenceNo() << ":" << tcpseg->sequenceNo()+tcpseg->payloadLength();
00109         out << "(" << tcpseg->payloadLength() << ") ";
00110     }
00111 
00112     // ack
00113     if (tcpseg->ackBit())
00114         out << "ack " << tcpseg->ackNo() << " ";
00115 
00116     // window
00117     out << "win " << tcpseg->window() << " ";
00118 
00119     // urgent
00120     if (tcpseg->urgBit())
00121         out << "urg " << tcpseg->urgentPointer() << " ";
00122 
00123     // options (not supported by TCPSegment yet)
00124 
00125     // comment
00126     if (comment)
00127         out << "# " << comment;
00128 
00129     out << endl;
00130 }

void TCPDumper::dump bool  l2r,
const char *  label,
IPDatagram *  dgram,
const char *  comment = NULL
 

00029 {
00030     cMessage *encapmsg = dgram->encapsulatedMsg();
00031     if (dynamic_cast<TCPSegment *>(encapmsg))
00032     {
00033         // if TCP, dump as TCP
00034         dump(l2r, label, (TCPSegment *)encapmsg, dgram->srcAddress().str(), dgram->destAddress().str(), comment);
00035     }
00036     else
00037     {
00038         // some other packet, dump what we can
00039         std::ostream& out = *outp;
00040 
00041         // seq and time (not part of the tcpdump format)
00042         char buf[30];
00043         sprintf(buf,"[%.3f%s] ", simulation.simTime(), label);
00044         out << buf;
00045 
00046         // packet class and name
00047         out << "? " << encapmsg->className() << " \"" << encapmsg->name() << "\"\n";
00048     }
00049 }

void TCPDumper::dumpIPv6 bool  l2r,
const char *  label,
IPv6Datagram_Base *  dgram,
const char *  comment = NULL
 

00053 {
00054     cMessage *encapmsg = dgram->encapsulatedMsg();
00055     if (dynamic_cast<TCPSegment *>(encapmsg))
00056     {
00057         // if TCP, dump as TCP
00058         dump(l2r, label, (TCPSegment *)encapmsg, dgram->srcAddress().str(), dgram->destAddress().str(), comment);
00059     }
00060     else
00061     {
00062         // some other packet, dump what we can
00063         std::ostream& out = *outp;
00064 
00065         // seq and time (not part of the tcpdump format)
00066         char buf[30];
00067         sprintf(buf,"[%.3f%s] ", simulation.simTime(), label);
00068         out << buf;
00069 
00070         // packet class and name
00071         out << "? " << encapmsg->className() << " \"" << encapmsg->name() << "\"\n";
00072     }
00073 }


Member Data Documentation

std::ostream* TCPDumper::outp [protected]
 

int TCPDumper::seq [protected]
 


The documentation for this class was generated from the following files:
Generated on Sat Apr 1 20:52:24 2006 for INET Framework for OMNeT++/OMNEST by  doxygen 1.4.1