Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 #ifndef __TCPDUMP_H
00021 #define __TCPDUMP_H
00022 
00023 #include <omnetpp.h>
00024 #include <assert.h>
00025 #include "IPAddress.h"
00026 
00027 #include "IPDatagram.h"
00028 #include "SCTPMessage.h"
00029 #include "TCPSegment.h"
00030 #include "IPv6Datagram_m.h"
00031 
00032 #define PCAP_MAGIC           0xa1b2c3d4
00033 #define RBUFFER_SIZE 65535
00034 
00035 
00036 struct pcap_hdr {
00037      uint32 magic;      
00038      uint16 version_major;   
00039      uint16 version_minor;   
00040      uint32 thiszone;   
00041      uint32 sigfigs;        
00042      uint32 snaplen;        
00043      uint32 network;        
00044 };
00045 
00046 
00047 struct pcaprec_hdr {
00048      int32  ts_sec;     
00049      uint32 ts_usec;        
00050      uint32 incl_len;   
00051      uint32 orig_len;   
00052 };
00053 
00054 typedef struct {
00055      uint8  dest_addr[6];
00056      uint8  src_addr[6];
00057      uint16 l3pid;
00058 } hdr_ethernet_t;
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00070 class TCPDumper
00071 {
00072     protected:
00073         int32 seq;
00074         std::ostream *outp;
00075     public:
00076         TCPDumper(std::ostream& o);
00077         ~TCPDumper();
00078         inline void setVerbosity(const int32 verbosityLevel) {
00079             verbosity = verbosityLevel;
00080         }
00081         void ipDump(const char *label, IPDatagram *dgram, const char *comment=NULL);
00082         void sctpDump(const char *label, SCTPMessage *sctpmsg, const std::string& srcAddr, const std::string& destAddr, const char *comment=NULL);
00083         
00084         void dump(const char *label, const char *msg);
00085         void tcpDump(bool l2r, const char *label, IPDatagram *dgram, const char *comment=NULL);
00086         void tcpDump(bool l2r, const char *label, TCPSegment *tcpseg, const std::string& srcAddr, const std::string& destAddr, const char *comment=NULL);
00087         void dumpIPv6(bool l2r, const char *label, IPv6Datagram_Base *dgram, const char *comment=NULL);
00088         void udpDump(bool l2r, const char *label, IPDatagram *dgram, const char *comment);
00089         const char* intToChunk(int32 type);
00090         FILE *dumpfile;
00091     private:
00092         int verbosity;
00093 };
00094 
00095 
00099 class INET_API TCPDump : public cSimpleModule
00100 {
00101     protected:
00102         unsigned char* ringBuffer[RBUFFER_SIZE];
00103         TCPDumper tcpdump;
00104         unsigned int snaplen;
00105         unsigned long first, last, space;
00106 
00107     public:
00108 
00109         TCPDump();
00110         ~TCPDump();
00111         virtual void handleMessage(cMessage *msg);
00112         virtual void initialize();
00113         virtual void finish();
00114 };
00115 
00116 #endif
00117 
00118