1 /******************************************************************************
9 Description: Declarations of encapsulation functions for ltp2tcp
11 ******************************************************************************/
15 #include <netinet/if_ether.h>
16 #include <netinet/ip.h>
23 /* Encapsulation Operations*/
25 /* Handle all headers up to LTP:
26 * h is the libpcap header. It should be returned with the Link+IP length in it.
27 * odata is the packet being processed starting at the Link header. It should be returned starting at the LTP header.
28 * ndata is the new packet. It should be returned with a Link+IP header in it.
29 * olength is the length of the packet being processed. It should be returned as the length of the LTP segment.
30 * nlength is the remaining length of the new packet. The Link+IP headers should be subtracted from it.
33 * 1)IP must say that TCP is next header
34 * 2)Initialize encapsulation private data as needed (typically store h and Link+IP header for fin() method)
36 int (*pre)(struct pcap_pkthdr *h, const u_char **odata, u_char **ndata, int* olength, int* nlength);
38 * Do any needed post processing on packet:
39 * tlen is the length of the TCP segment (data+header)
40 * data is the new packet starting at the link header
42 * Typically update IP length
44 int (*post)(int tlen, u_char *data);
46 * Add a TCP initial Threeway handshake to the connection:
47 * h is the libpcap header of the current packet.
49 * This means create three packets:
50 * SYN in current Direction (SEQ=0,ACK=0)
51 * SYN,ACK in opposite Direction (SEQ=0,ACK=1)
52 * ACK in current Direction (SEQ=1,ACK=1)
54 * You typically need Link+IP header from private data
55 * Output packets to state.out
57 int (*handshake)(struct pcap_pkthdr *h);
59 * Add TCP closing handshake:
60 * This means create three packets:
61 * FIN,ACK in current Direction (SEQ=state.seq_num+1, ACK=state.ack_num)
62 * FIN,ACK in opposite Direction (SEQ=state.ack_num, ACK=state.seq_num+2)
63 * ACK in current Direction (SEQ=state.seq_num+2,ACK=state.ack_num+1)
65 * You typically need the libpcap header and the Link+IP header from private data
66 * Output packets to state.out
72 /*Encapsulation Operations Structures*/
73 extern struct encap_ops udp_encap;
74 extern struct encap_ops dccp_encap;
75 extern struct encap_ops sll_encap;
78 /*Encapsulation Selector*/
79 void encap_sel(char* string);
81 /*Standard Ethernet, IP encapsulation structures and functions*/
83 struct pcap_pkthdr header;
84 u_char od[sizeof(struct ether_header)+sizeof(struct iphdr)];
87 int fill_eip4_encap(struct eip4_en_p *eip, const u_char* data, int dlen, struct pcap_pkthdr *h);
88 int eip4_post(struct eip4_en_p *eip, int tlen, u_char* data);
89 int eip4_handshake(struct eip4_en_p *eip, struct pcap_pkthdr *h);
90 int eip4_fin(struct eip4_en_p *eip);