00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _DATALINK_H_
00011 #define _DATALINK_H_
00012
00013 #include "usi-structs.h"
00014 #include "RX.h"
00015 #include <stdio.h>
00016
00017
00018
00019 namespace usipp {
00020
00024 class Pcap : public RX {
00025 private:
00026 struct timeval d_tv;
00027
00028
00029 int d_datalink;
00030 size_t d_framelen, d_snaplen;
00031
00032
00033 pcap_t *d_pd;
00034
00035
00036 bpf_u_int32 d_localnet, d_netmask;
00037
00038
00039 struct bpf_program d_filter;
00040
00041
00042 struct pcap_pkthdr d_phdr;
00043
00044
00045 char d_dev[10];
00046 int d_has_promisc;
00047
00048
00049 bool d_timeout;
00050
00051 protected:
00052 struct ether_header d_ether;
00053 char d_filter_string[1000];
00054
00055 public:
00056
00062 Pcap(char *);
00063
00064 Pcap();
00065
00068 Pcap(const Pcap &);
00069
00070 virtual ~Pcap();
00071
00072 Pcap &operator=(const Pcap &);
00073
00074
00079 char *get_hwsrc(char *, size_t);
00080
00085 char *get_hwdst(char *, size_t);
00086
00090 u_int16_t get_etype();
00091
00094 int get_datalink();
00095
00099 int get_framelen();
00100
00106 virtual int init_device(char *dev, int promisc, size_t snaplen);
00107
00110 virtual int setfilter(char *filter);
00111
00114 virtual int sniffpack(void *, size_t);
00115
00117 void *get_frame(void *, size_t);
00118
00120 pcap_t *pcap() { return d_pd; }
00121
00123 int timeout(struct timeval);
00124
00126 bool timeout();
00127
00128 };
00129
00130
00131 }
00132
00133 #endif // _DATALINK_H_