00001
00007 #ifndef NETSNIFF_H_
00008 #define NETSNIFF_H_
00009
00010 #include <arpa/inet.h>
00011 #include <iostream>
00012 #include <sstream>
00013 #include <pcap.h>
00014 #include "Debug.h"
00015 #include "SIPPacket.h"
00016 #include "PacketHandler.h"
00017
00018 using namespace std;
00019 using namespace debug;
00020
00022
00027 namespace network
00028 {
00029
00031
00035 class NetSniff
00036 {
00037 public:
00044 NetSniff(string device, string sniffport, string sniffproto);
00046 virtual ~NetSniff();
00052 bool isReady();
00058 bool Open();
00065 bool ApplyFilter(const char* filter);
00067 void startsniff();
00069 void stopsniff();
00074 void setDebugger(Debug *dbg);
00080 bool isSniffing();
00085 void SetShow(bool option);
00091 void SetCapture(bool option, string captpath);
00096 string GetFullStatus();
00097
00098 protected:
00100 char dev[32];
00102 char sstr[2048];
00104 char BPFfilter[2048];
00106 char port[5];
00108 char snfproto[5];
00110 char header[128];
00112 int sniffed;
00114 int displayed;
00116 int stored;
00118 pcap_t *sniff;
00120 struct bpf_program fp;
00122 bpf_u_int32 ip;
00124 bpf_u_int32 mask;
00125 private:
00127 bool ready;
00129
00135 struct iphdr {
00137 u_char ip_vhl;
00139 u_char ip_tos;
00141 u_short ip_len;
00143 u_short ip_id;
00145 u_short ip_off;
00147 #define IP_RF 0x8000
00149 #define IP_DF 0x4000
00151 #define IP_MF 0x2000
00153 #define IP_OFFMASK 0x1fff
00155 u_char ip_ttl;
00157 u_char ip_p;
00159 u_short ip_sum;
00161 u_char ip_src1,ip_src2,ip_src3,ip_src4;
00163 u_char ip_dst1,ip_dst2,ip_dst3,ip_dst4;
00164 };
00169 string HWAddress(u_char *ptr);
00171 bool dosniff;
00173 Debug *dbg;
00175 bool debug;
00177 bool snfshow;
00179 bool snfcap;
00181 string snfcappath;
00183 string file;
00185 ostringstream dbgbuffer;
00191 void PrintPacket(const u_char *data, const struct pcap_pkthdr *h);
00193 SIPPacket* sipp;
00195 PacketHandler pkghand;
00196 };
00197 }
00198
00199 #endif