datalink.h Source File

Main Page Class Hierarchy Compound List File List Compound Members Examples

# datalink.h

    00001 /*** This Programs/Libraries are (C)opyright by Sebastian Krahmer.
    00002  *** You may use it under the terms of the GPL. You should have
    00003  *** already received the file COPYING that shows you your rights.
    00004  *** Please look at COPYING for further license-details.
    00005  ***
    00006  *** THERE IS ABSOLUTELY NO WARRANTY. SO YOU USE IT AT YOUR OWN RISK.
    00007  *** IT WAS WRITTEN IN THE HOPE THAT IT WILL BE USEFULL. I AM NOT RESPONSIBLE
    00008  *** FOR ANY DAMAGE YOU MAYBE GET DUE TO USING MY PROGRAMS.
    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 //#include "config.h"
    00018
    00019 namespace usipp {
    00020
    00024 class Pcap : public RX {
    00025 private:
    00026         struct timeval d_tv;
    00027
    00028         // Heavily used by libpcap
    00029         int d_datalink;
    00030         size_t d_framelen, d_snaplen;
    00031
    00032         // pcap-descriptor
    00033         pcap_t *d_pd;
    00034
    00035         // netaddress and netmask
    00036         bpf_u_int32 d_localnet, d_netmask;
    00037
    00038         // The actual filter-program
    00039         struct bpf_program d_filter;
    00040
    00041         // The pcap-header for every packet fetched
    00042         struct pcap_pkthdr d_phdr;
    00043
    00044         // filled by init_device()
    00045         char d_dev[10];
    00046         int d_has_promisc;
    00047
    00048         // true when timed out
    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 }; // class Datalink {}
    00129
    00130
    00131 } // namespace usipp
    00132
    00133 #endif // _DATALINK_H_