ekg2

plugins/sniff/sniff_ip.h

Idź do dokumentacji tego pliku.
00001 /* XXX, check includes */
00002 #include <stdio.h>
00003 #include <signal.h>
00004 #include <pcap.h>
00005 
00006 #include <sys/types.h>
00007 #include <sys/socket.h>
00008 #include <netinet/in.h>
00009 #include <arpa/inet.h>
00010 
00011 #define SIZE_ETHERNET 14 /* ethernet headers are always exactly 14 bytes [1] */
00012 #define ETHER_ADDR_LEN 6 /* Ethernet addresses are 6 bytes */
00013 
00014 struct ethhdr { /* Ethernet header */
00015         u_char  ether_dhost[ETHER_ADDR_LEN];    /* destination host address */
00016         u_char  ether_shost[ETHER_ADDR_LEN];    /* source host address */
00017         u_short ether_type;                     /* IP? ARP? RARP? etc */
00018 };
00019 
00020 /* from tcpdump sll.h */
00021 
00022 #define SIZE_SLL        16              /* total header length */
00023 #define SLL_ADDRLEN     8               /* length of address field */
00024 
00025 struct sll_header {
00026         u_int16_t       sll_pkttype;    /* packet type */
00027         u_int16_t       sll_hatype;     /* link-layer address type */
00028         u_int16_t       sll_halen;      /* link-layer address length */
00029         u_int8_t        sll_addr[SLL_ADDRLEN];  /* link-layer address */
00030         u_int16_t       sll_protocol;   /* protocol */
00031 };
00032 
00033 struct iphdr { /* IP header */
00034 //        u_char  ip_vhl;                 /* version << 4 | header length >> 2 */
00035         unsigned int ip_hl:4;               /* header length */
00036         unsigned int ip_v:4;                /* version */
00037         
00038         u_char  ip_tos;                 /* type of service */
00039         u_short ip_len;                 /* total length */
00040         u_short ip_id;                  /* identification */
00041         u_short ip_off;                 /* fragment offset field */
00042         #define IP_RF 0x8000            /* reserved fragment flag */
00043         #define IP_DF 0x4000            /* dont fragment flag */
00044         #define IP_MF 0x2000            /* more fragments flag */
00045         #define IP_OFFMASK 0x1fff       /* mask for fragmenting bits */
00046         u_char  ip_ttl;                 /* time to live */
00047         u_char  ip_p;                   /* protocol */
00048         u_short ip_sum;                 /* checksum */
00049         struct  in_addr ip_src,ip_dst;  /* source and dest address */
00050 };
00051 
00052 typedef u_int tcp_seq;
00053 
00054 struct tcphdr { /* TCP header */
00055         u_short th_sport;               /* source port */
00056         u_short th_dport;               /* destination port */
00057         tcp_seq th_seq;                 /* sequence number */
00058         tcp_seq th_ack;                 /* acknowledgement number */
00059         u_char  th_offx2;               /* data offset, rsvd */
00060 #define TH_OFF(th)      (((th)->th_offx2 & 0xf0) >> 4)
00061         u_char  th_flags;
00062         u_short th_win;                 /* window */
00063         u_short th_sum;                 /* checksum */
00064         u_short th_urp;                 /* urgent pointer */
00065 };
00066 
00067 #define TH_FIN  0x01
00068 #define TH_SYN  0x02
00069 #define TH_RST  0x04
00070 #define TH_PUSH 0x08
00071 #define TH_ACK  0x10
00072 #define TH_URG  0x20
00073 #define TH_ECE  0x40
00074 #define TH_CWR  0x80
00075 
00076 #define TH_FLAGS        (TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG|TH_ECE|TH_CWR)
00077 
00078 struct udphdr { /* UDP header */
00079         u_short th_sport;               /* source port */
00080         u_short th_dport;               /* destination port */
00081         u_short th_len;                 /* length */
00082         u_short th_sum;                 /* checksum */
00083 };
00084 
00085 struct icmphdr { /* ICMP header */
00086         u_char icmp_type;
00087         u_char icmp_code;
00088         u_short icmp_cksum;
00089 };
00090 
00091 #define ETHERTYPE_IP            0x0800          /* IP */
00092 #define ETHERTYPE_ARP           0x0806          /* Address resolution */
00093 
 All Struktury Danych Pliki Funkcje Zmienne Definicje typów Wyliczenia Wartości wyliczeń Definicje