]> sjero.net Git - dccp2tcp/blob - dccp2tcp.h
Ignore directory of CCID 2 captures
[dccp2tcp] / dccp2tcp.h
1 /******************************************************************************
2 Author: Samuel Jero
3
4 Date: 7/2011
5
6 Description: Header file for program to convert a DCCP flow to a TCP flow for DCCP
7                  analysis via tcptrace.
8
9 Notes:
10         1)CCID2 ONLY
11         2)DCCP MUST use 48 bit sequence numbers
12         3)Checksums are not computed (they are zeroed)
13         4)Only implements those packet types normally used in a session
14         5)DCCP Ack packets show up as TCP packets containing one byte
15         6)Very little error checking of packet headers
16 ******************************************************************************/
17 #ifndef _DCCP2TCP_H
18 #define _DCCP2TCP_H
19
20 #include <stdarg.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <strings.h>
25 #include <sys/types.h>
26 #include <unistd.h>
27 #include <time.h>
28 #include <sys/time.h>
29 #include <sys/socket.h>
30 #include <net/if.h>
31 #include <netinet/in.h>
32 #include <netinet/in_systm.h>
33 #include <arpa/inet.h>
34 #include <netinet/if_ether.h>
35 #include <netinet/ip.h>
36 #include <netinet/tcp.h>
37 #include <netinet/tcp.h>
38 #include <netinet/udp.h>
39 #include <netdb.h>
40 #include <ctype.h>
41 #include <pcap.h>
42 #include <linux/dccp.h>
43
44
45 #define MAX_PACKET      1600    /*Maximum size of TCP packet */
46 #define TBL_SZ          40000   /*Size of Sequence Number Table*/
47
48
49
50
51 /*Packet structure*/
52 struct packet{
53         struct pcap_pkthdr      *h;             /*libpcap header*/
54         u_char                          *data;  /*Packet Data*/
55         int                                     length; /*Packet length*/
56         uint32_t                        src_id; /*Source ID of packet*/
57         uint32_t                        dest_id; /*Destination ID of packet*/
58 };
59
60 /*Constant Packet structure*/
61 struct const_packet{
62         const struct pcap_pkthdr *h;    /*libpcap header*/
63         const u_char                    *data;  /*Packet Data*/
64         int                                             length; /*Packet length*/
65         uint32_t                                src_id; /*Source ID of packet*/
66         uint32_t                                dest_id;/*Destination ID of packet*/
67 };
68
69 /*Connection states*/
70 enum con_state{
71         INIT,
72         OPEN,
73         CLOSE,
74 };
75
76 /*Host---half of a connection*/
77 struct host{
78         uint32_t                        id;             /*Host ID*/
79         __be16                          port;   /*Host DCCP port*/
80         struct tbl                      *table; /*Host Sequence Number Table*/
81         int                                     size;   /*Size of Sequence Number Table*/
82         int                                     cur;    /*Current TCP Sequence Number*/
83         enum con_state          state;  /*Connection state*/
84 };
85
86 /*Connection structure*/
87 struct connection{
88         struct connection       *next;  /*List pointer*/
89         struct host                     A;              /*Host A*/
90         struct host                     B;              /*Host B*/
91 };
92
93 /*sequence number table structure */
94 struct tbl{
95         __be32                          old;    /*DCCP sequence number */
96         u_int32_t                       new;    /*TCP sequence number */
97         int                                     size;   /*packet size*/
98         enum dccp_pkt_type      type;   /*packet type*/
99 };
100
101 /*Option flags*/
102 extern int debug;               /*set to 1 to turn on debugging information*/
103 extern int yellow;              /*tcptrace yellow line as currently acked packet*/
104 extern int green;               /*tcptrace green line as currently acked packet*/
105 extern int sack;                /*add TCP SACKS*/
106
107 extern struct connection *chead;/*connection list*/
108
109
110 /*debug printf
111  * Levels:
112  *      0) Always print even if debug isn't specified
113  *  1) Errors and warnings... Don't overload the screen with too much output
114  *  2) Notes and per-packet processing info... as verbose as needed
115  */
116 void dbgprintf(int level, const char *fmt, ...);
117
118 /*Function to parse encapsulation*/
119 int do_encap(int link, struct packet *new, const struct const_packet *old);
120
121 /*Connection functions*/
122 int get_host(uint32_t src_id, uint32_t dest_id, int src_port, int dest_port, struct host **fwd, struct host **rev);
123 struct connection *add_connection(uint32_t src_id, uint32_t dest_id, int src_port, int dest_port);
124 int update_state(struct host* hst, enum con_state st);
125
126 #endif