]> sjero.net Git - ltp2tcp/blob - SLL.patch
Initial Commit
[ltp2tcp] / SLL.patch
1 diff -r ab54ffb0cb71 Makefile
2 --- a/Makefile  Fri Mar 04 11:30:16 2011 -0500
3 +++ b/Makefile  Thu May 19 01:11:51 2011 -0400
4 @@ -22,8 +22,8 @@
5  
6  all: ltptrace
7  
8 -ltptrace: main.o ltp.o encap.o udp.o dccp.o Makefile
9 -       gcc ${CFLAGS} ${LDLIBS} --std=gnu99 main.o ltp.o encap.o udp.o dccp.o -oltptrace
10 +ltptrace: main.o ltp.o encap.o udp.o dccp.o sll.o Makefile
11 +       gcc ${CFLAGS} ${LDLIBS} --std=gnu99 main.o ltp.o encap.o udp.o dccp.o sll.o -oltptrace
12         
13  main.o: ltp2tcp.c ltp2tcp.h
14         gcc -c ${CFLAGS} ${LDLIBS} --std=gnu99 ltp2tcp.c -omain.o
15 @@ -40,6 +40,9 @@
16  dccp.o: dccp_encap.c encap.h ltp2tcp.h
17         gcc -c ${CFLAGS} ${LDLIBS} --std=gnu99 dccp_encap.c -odccp.o
18  
19 +sll.o: sll_encap.c encap.h ltp2tcp.h
20 +       gcc -c ${CFLAGS} ${LDLIBS} --std=gnu99 sll_encap.c -osll.o
21 +
22  
23  install: ltptrace
24         install -m 755 -o bin -g bin ltptrace ${BINDIR}/ltptrace
25 diff -r ab54ffb0cb71 encap.c
26 --- a/encap.c   Fri Mar 04 11:30:16 2011 -0500
27 +++ b/encap.c   Thu May 19 01:11:51 2011 -0400
28 @@ -20,6 +20,10 @@
29                 state.en_ops=&dccp_encap;
30                 return;
31         }
32 +       if(strcmp(string, "sll")==0 || strcmp(string,"SLL")==0){ /*SLL (Linux Cooked Capture)*/
33 +                       state.en_ops=&sll_encap;
34 +                       return;
35 +               }
36         printf("Encapsulation type: %s is not supported\n", string);
37         exit(1);
38  return;
39 @@ -245,7 +249,6 @@
40         u_char                          *ptr;
41         struct pcap_pkthdr      nh;
42         u_int32_t                       temp;
43 -       struct udp_en_p         *uep;
44  
45         /*Safety Check*/
46         if(eip==NULL){
47 @@ -275,7 +278,6 @@
48  
49                 /* Copy Ethernet and IP headers from private data area*/
50                 /* These are headers from the first packet in the capture*/
51 -               uep=(struct udp_en_p *) state.en_priv;
52                 memcpy(ptr, eip->od, sizeof(struct ether_header)+ sizeof(struct iphdr));
53  
54                 /*Adjust IP header*/
55 diff -r ab54ffb0cb71 LTP connection visualization/encap.h
56 --- a/LTP connection visualization/encap.h      Fri Mar 04 11:30:16 2011 -0500
57 +++ b/LTP connection visualization/encap.h      Thu May 19 01:11:51 2011 -0400
58 @@ -68,6 +68,7 @@
59  /*Encapsulation Operations Structures*/
60  extern struct encap_ops udp_encap;
61  extern struct encap_ops dccp_encap;
62 +extern struct encap_ops sll_encap;
63  
64  
65  /*Encapsulation Selector*/
66 diff -r ab54ffb0cb71 sll_encap.c
67 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
68 +++ b/sll_encap.c       Thu May 19 01:11:51 2011 -0400
69 @@ -0,0 +1,487 @@
70 +/******************************************************************************
71 +Author: Samuel Jero
72 +
73 +Date: 5/2011
74 +
75 +Description:  <SLL, IPv4, UDP> encapsulation functions
76 +
77 +******************************************************************************/
78 +#include "ltp2tcp.h"
79 +#include <pcap/sll.h>
80 +#include <netinet/udp.h>
81 +
82 +extern int debug;
83 +
84 +
85 +
86 +/*SLL encapsulation private data structure*/
87 +struct sll_en_p{
88 +       int first;
89 +       struct pcap_pkthdr      header;
90 +       u_char                          od[sizeof(struct sll_header)+sizeof(struct iphdr)+sizeof(struct udphdr)];
91 +};
92 +
93 +
94 +/*Fill the encapsulation structure*/
95 +int fill_sllip4_encap(struct sll_en_p *slip, const u_char* data, int dlen, struct pcap_pkthdr *h){
96 +       /*safety check*/
97 +       if(slip==NULL || data==NULL || h==NULL || dlen < sizeof(struct sll_header)+sizeof(struct iphdr)){
98 +               dbgprintf(1, "Error: SLL, IPv4 Encapsulation method given bad data!\n");
99 +               return -1;
100 +       }
101 +
102 +       if(slip->first==0){
103 +               /* First time, allocate memory and copy libpcap header and encap headers
104 +                * this guarantees the IP "direction" of the encap headers */
105 +               memcpy(&slip->header, h, sizeof(struct pcap_pkthdr));
106 +               memcpy(slip->od, data,sizeof(struct sll_header)+sizeof(struct iphdr));
107 +               slip->first=1;
108 +       }else{
109 +               /* Just update the libpcap header (and associated timestamp)*/
110 +               memcpy(&slip->header, h, sizeof(struct pcap_pkthdr));
111 +       }
112 +       return 0;
113 +}
114 +
115 +/* encapsulation manipulation previous to packet conversion */
116 +int sll_encap_pre(struct pcap_pkthdr *h, const u_char **odata, u_char **ndata, int* olength, int* nlength)
117 +{
118 +       struct iphdr                    *iph;
119 +       struct sll_header               *slh;
120 +       struct udphdr                   *udph;
121 +
122 +       /*Safety checks*/
123 +       if(!h || !odata || !ndata || !*odata || !*ndata || !olength || !nlength){
124 +               dbgprintf(0,"Error: SLL Encapsulation given bad data!\n");
125 +               exit(1);
126 +       }
127 +       if(*olength < sizeof(struct ether_header)+sizeof(struct iphdr)+sizeof(struct udphdr)
128 +                       || *nlength < sizeof(struct ether_header)+sizeof(struct iphdr)+sizeof(struct tcphdr)){
129 +                       dbgprintf(0, "Error: SLL Encapsulation given packet of wrong size!\n");
130 +                       return -1;
131 +       }
132 +
133 +       /*initialize encapsulation private data*/
134 +       if(state.en_priv==NULL){
135 +               /* First time, allocate memory and copy libpcap header and encap headers
136 +                * this guarantees the IP "direction" of the encap headers */
137 +               state.en_priv=malloc(sizeof(struct sll_en_p));
138 +               if(state.en_priv==NULL){
139 +                       dbgprintf(0,"Error: Couldn't allocate Memory\n");
140 +                       exit(1);
141 +               }
142 +       }
143 +       if(fill_sllip4_encap((struct sll_en_p*)state.en_priv, *odata, *olength, h)<0){
144 +               return -1;
145 +       }
146 +
147 +       /*Copy SLL and IPv4 headers over*/
148 +       memcpy(*ndata, *odata, sizeof(struct sll_header)+sizeof(struct iphdr));
149 +       *odata+=sizeof(struct sll_header)+ sizeof(struct iphdr);
150 +       *ndata+=sizeof(struct sll_header)+ sizeof(struct iphdr);
151 +
152 +       /*Confirm that this is Ethernet and that IPv4 is next*/
153 +       slh=(struct sll_header*)(*odata -sizeof(struct sll_header)- sizeof(struct iphdr));
154 +       if(slh->sll_protocol!=htons(ETHERTYPE_IP)){
155 +               dbgprintf(1, "Note: Packet not SLL or Not IPv4 next\n");
156 +               return -1;
157 +       }
158 +
159 +       /* Check That this is IPv4 and that UDP is next*/
160 +       iph= (struct iphdr *) (*ndata - sizeof(struct iphdr));
161 +       if(iph->version!=4){
162 +               dbgprintf(1, "Note: Packet is not IPv4\n");
163 +               return -1;
164 +       }
165 +       if(iph->protocol!=0x11){
166 +               dbgprintf(1, "Note: Packet is not UDP\n");
167 +               return -1;
168 +       }
169 +
170 +       /*set ip to indicate that tcp is next protocol*/
171 +       iph->protocol=6;
172 +       iph->check=htonl(0);
173 +
174 +       /* Adjust libpcap headers*/
175 +       h->caplen=sizeof(struct sll_header) +sizeof(struct iphdr);
176 +       h->len=sizeof(struct sll_header) +sizeof(struct iphdr);
177 +
178 +       /*Adjust packet length*/
179 +       udph=(struct udphdr*)*odata;
180 +       *olength=ntohs(udph->len);
181 +
182 +       /*Adjust New Packet Length*/
183 +       *nlength-=sizeof(struct sll_header) +sizeof(struct iphdr);
184 +
185 +       /*Move Packet Pointer past UDP header*/
186 +       *odata+=sizeof(struct udphdr);
187 +return 0;
188 +}
189 +
190 +/* encapsulation manipulation after conversion */
191 +int sll_encap_post(int tlen, u_char *data)
192 +{
193 +       struct iphdr *iph;
194 +
195 +       /* Move data pointer to start of IPv4 header*/
196 +       data+=sizeof(struct sll_header);
197 +
198 +       /*Determine if the given length is reasonable*/
199 +       if((tlen+sizeof(struct iphdr)) > 0xFFFF){
200 +                       dbgprintf(1, "Error: Given TCP header+data length is too large for an IPv4 packet!\n");
201 +                       return -1;
202 +       }
203 +
204 +       /*Adjust IPv4 header to account for packet's total length*/
205 +       iph=(struct iphdr*)data;
206 +       iph->tot_len=htons(sizeof(struct iphdr)+tlen);
207 +       return 0;
208 +}
209 +
210 +/* Create a TCP three-way handshake */
211 +int sll_encap_handshake(struct pcap_pkthdr *h)
212 +{
213 +       struct iphdr            *iph;
214 +       struct tcphdr           *tcph;
215 +       u_char                          *data;
216 +       u_char                          *ptr;
217 +       struct pcap_pkthdr      nh;
218 +       u_int32_t                       temp;
219 +       struct sll_en_p         *slip=(struct sll_en_p*)state.en_priv;
220 +
221 +
222 +       /*Safety Check*/
223 +       if(h==NULL || state.en_priv==NULL){
224 +               dbgprintf(1, "Error: SLL, IPv4 Encapsulation handshake method given bad data!\n");
225 +               return -1;
226 +       }
227 +
228 +       /*create new libpcap header*/
229 +       memcpy(&nh, h, sizeof(struct pcap_pkthdr));
230 +
231 +       /*create buffer for new packet*/
232 +       ptr=data=malloc(MAX_PACKET);
233 +       if(data==NULL){
234 +               dbgprintf(0,"Error: Couldn't allocate Memory\n");
235 +               exit(1);
236 +       }
237 +
238 +       /* 1)Create Syn Packet*/
239 +               /*make sure the packet is all zero*/
240 +               memset(data, 0, MAX_PACKET);
241 +               ptr=data;
242 +
243 +               /*Set the libpcap header*/
244 +               nh.caplen=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr)+4;
245 +               nh.len=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr)+4;
246 +               nh.ts.tv_usec-=3000; /*Time comes from the first packet received, so make these packets earlier*/
247 +
248 +               /* Copy SLL and IP headers from private data area*/
249 +               /* These are headers from the first packet in the capture*/
250 +               memcpy(ptr, slip->od, sizeof(struct sll_header)+ sizeof(struct iphdr));
251 +
252 +               /*Adjust IP header*/
253 +               iph= (struct iphdr *) (ptr + sizeof(struct sll_header));
254 +               iph->protocol=6;
255 +               iph->check=htonl(0);
256 +               iph->tot_len=htons(sizeof(struct iphdr)+sizeof(struct tcphdr)+4);
257 +
258 +               /*Build TCP header*/
259 +               ptr+=sizeof(struct sll_header)+ sizeof(struct iphdr);
260 +               tcph=(struct tcphdr*)ptr;
261 +               tcph->source=htons(1113);
262 +               tcph->dest=htons(1113);
263 +               tcph->doff=6;
264 +               tcph->check=htonl(0);
265 +               tcph->urg_ptr=0;
266 +               tcph->urg=0;
267 +               tcph->psh=0;
268 +               tcph->fin=0;
269 +               tcph->syn=1;
270 +               tcph->rst=0;
271 +               tcph->ack=0;
272 +
273 +               /*Initialize Sequence and Acknowledgment Numbers and Window*/
274 +               tcph->seq=htonl(state.seq_num++);
275 +               tcph->ack_seq=htonl(0);
276 +               tcph->window=htons(WIN_FACTOR);
277 +
278 +               /* Add SACK permitted option*/
279 +               ptr+=sizeof(struct tcphdr);
280 +               *ptr=4;
281 +               ptr++;
282 +               *ptr=2;
283 +
284 +               /*Save To Packet Capture*/
285 +               pcap_dump((u_char*)state.out,&nh, data);
286 +
287 +
288 +       /* 2)Create Syn,Ack Packet*/
289 +               /*make sure the packet is all zero*/
290 +               memset(data, 0, MAX_PACKET);
291 +               ptr=data;
292 +
293 +               /*Set the libpcap header*/
294 +               nh.caplen=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr)+4;
295 +               nh.len=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr)+4;
296 +               nh.ts.tv_usec+=1000; /*This packet is 1/3rd closer to the first packet then the previous packet created*/
297 +
298 +               /* Copy SLL and IP headers from private data area*/
299 +               /* These are headers from the first packet in the capture*/
300 +               memcpy(data, slip->od, sizeof(struct sll_header)+ sizeof(struct iphdr));
301 +
302 +               /*Adjust IP header, including swapping source and destination*/
303 +               iph= (struct iphdr *) (ptr + sizeof(struct sll_header));
304 +               iph->protocol=6;
305 +               iph->check=htonl(0);
306 +               temp=iph->saddr;
307 +               iph->saddr=iph->daddr;
308 +               iph->daddr=temp;
309 +               iph->tot_len=htons(sizeof(struct iphdr)+sizeof(struct tcphdr)+4);
310 +
311 +               /*Build TCP header*/
312 +               ptr+=sizeof(struct sll_header)+ sizeof(struct iphdr);
313 +               tcph=(struct tcphdr*)ptr;
314 +               tcph->source=htons(1113);
315 +               tcph->dest=htons(1113);
316 +               tcph->doff=6;
317 +               tcph->check=htonl(0);
318 +               tcph->urg_ptr=0;
319 +               tcph->urg=0;
320 +               tcph->psh=0;
321 +               tcph->fin=0;
322 +               tcph->syn=1;
323 +               tcph->rst=0;
324 +               tcph->ack=1;
325 +
326 +               /*Initialize Sequence and Acknowledgement Numbers and Window*/
327 +               tcph->seq=htonl(state.ack_num++);
328 +               tcph->ack_seq=htonl(state.seq_num);
329 +               tcph->window=htons(WIN_FACTOR);
330 +
331 +               /* Add SACK permitted option*/
332 +               ptr+=sizeof(struct tcphdr);
333 +               *ptr=4;
334 +               ptr++;
335 +               *ptr=2;
336 +
337 +               /*Save To Packet Capture*/
338 +               pcap_dump((u_char*)state.out,&nh, data);
339 +
340 +       /* 3)Create Ack Packet*/
341 +               /*make sure the packet is all zero*/
342 +               memset(data, 0, MAX_PACKET);
343 +               ptr=data;
344 +
345 +               /*Set the libpcap header*/
346 +               nh.caplen=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr);
347 +               nh.len=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr);
348 +               nh.ts.tv_usec+=1000; /*This packet is 2/3rds between SYN and first packet*/
349 +
350 +               /* Copy SLL and IP headers from private data area*/
351 +               /* These are headers from the first packet in the capture*/
352 +               memcpy(data, slip->od, sizeof(struct sll_header)+ sizeof(struct iphdr));
353 +
354 +               /*Adjust IP header*/
355 +               iph= (struct iphdr *) (ptr + sizeof(struct sll_header));
356 +               iph->protocol=6;
357 +               iph->check=htonl(0);
358 +               iph->tot_len=htons(sizeof(struct iphdr)+sizeof(struct tcphdr));
359 +
360 +               /*Build TCP header*/
361 +               ptr+=sizeof(struct sll_header)+ sizeof(struct iphdr);
362 +               tcph=(struct tcphdr*)ptr;
363 +               tcph->source=htons(1113);
364 +               tcph->dest=htons(1113);
365 +               tcph->doff=5;
366 +               tcph->check=htonl(0);
367 +               tcph->urg_ptr=0;
368 +               tcph->urg=0;
369 +               tcph->psh=0;
370 +               tcph->fin=0;
371 +               tcph->syn=0;
372 +               tcph->rst=0;
373 +               tcph->ack=1;
374 +
375 +               /*Initialize Sequence and Acknowledgement numbers and window*/
376 +               tcph->seq=htonl(state.seq_num++);
377 +               tcph->ack_seq=htonl(state.ack_num);
378 +               tcph->window=htons(WIN_FACTOR);
379 +
380 +               /*Save To Packet Capture*/
381 +               pcap_dump((u_char*)state.out,&nh, data);
382 +               return 0;
383 +}
384 +
385 +/* Create a TCP ending handshake */
386 +int sll_encap_fin()
387 +{
388 +       struct iphdr            *iph;
389 +       struct tcphdr           *tcph;
390 +       u_char                          *data;
391 +       u_char                          *ptr;
392 +       struct pcap_pkthdr      nh;
393 +       u_int32_t                       temp;
394 +       struct sll_en_p         *slip=(struct sll_en_p*)state.en_priv;
395 +
396 +       /*Safety Check*/
397 +       if(slip==NULL){
398 +               dbgprintf(1,"Error: SLL, IPv4 Encapsulation Finish method given invalid data!\n");
399 +               return -1;
400 +       }
401 +
402 +       /*copy the libpcap header from private data area*/
403 +       memcpy(&nh, &slip->header, sizeof(struct pcap_pkthdr));
404 +
405 +       /*create buffer for new packet*/
406 +       ptr=data=malloc(MAX_PACKET);
407 +       if(data==NULL){
408 +               dbgprintf(0,"Error: Couldn't allocate Memory\n");
409 +               exit(1);
410 +       }
411 +
412 +       /* 1)Create Fin Packet*/
413 +               /*make sure the packet is all zero*/
414 +               memset(data, 0, MAX_PACKET);
415 +               ptr=data;
416 +
417 +               /*Set the libpcap header*/
418 +               nh.caplen=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr);
419 +               nh.len=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr);
420 +               nh.ts.tv_usec+=1000; /*Time is from the last packet in the capture; make this packet after that packet*/
421 +
422 +               /* Copy Ethernet and IP headers from private data area*/
423 +               /* These are headers from the first packet in the capture*/
424 +               memcpy(ptr, slip->od, sizeof(struct sll_header)+ sizeof(struct iphdr));
425 +
426 +               /*Adjust IP header*/
427 +               iph= (struct iphdr *) (ptr + sizeof(struct sll_header));
428 +               iph->protocol=6;
429 +               iph->check=htonl(0);
430 +               iph->tot_len=htons(sizeof(struct iphdr)+sizeof(struct tcphdr));
431 +
432 +               /*Build TCP header*/
433 +               ptr+=sizeof(struct sll_header)+ sizeof(struct iphdr);
434 +               tcph=(struct tcphdr*)ptr;
435 +               tcph->source=htons(1113);
436 +               tcph->dest=htons(1113);
437 +               tcph->doff=5;
438 +               tcph->check=htonl(0);
439 +               tcph->urg_ptr=0;
440 +               tcph->urg=0;
441 +               tcph->psh=0;
442 +               tcph->fin=1;
443 +               tcph->syn=0;
444 +               tcph->rst=0;
445 +               tcph->ack=1;
446 +
447 +               /* Adjust Sequence and Acknowledgment numbers and window*/
448 +               tcph->seq=htonl(++state.seq_num);
449 +               tcph->ack_seq=htonl(state.ack_num);
450 +               tcph->window=htons(WIN_FACTOR);
451 +
452 +               /*Update Sequence Number to include the fin packet in the sequence number space*/
453 +               state.seq_num++;
454 +
455 +               /* Save To Packet Capture*/
456 +               pcap_dump((u_char*)state.out,&nh, data);
457 +
458 +       /* 2)Create Fin,Ack Packet*/
459 +               /*make sure the packet is all zero*/
460 +               memset(data, 0, MAX_PACKET);
461 +               ptr=data;
462 +
463 +               /*Set the libpcap header*/
464 +               nh.caplen=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr);
465 +               nh.len=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr);
466 +               nh.ts.tv_usec+=1000; /*After the previous packet*/
467 +
468 +               /* Copy Ethernet and IP headers from private data area*/
469 +               /* These are headers from the first packet in the capture*/
470 +               memcpy(ptr, slip->od, sizeof(struct sll_header)+ sizeof(struct iphdr));
471 +
472 +               /*Update IP header, including swapping source and destination addresses*/
473 +               iph= (struct iphdr *) (ptr + sizeof(struct sll_header));
474 +               iph->protocol=6;
475 +               iph->check=htonl(0);
476 +               temp=iph->saddr;
477 +               iph->saddr=iph->daddr;
478 +               iph->daddr=temp;
479 +               iph->tot_len=htons(sizeof(struct iphdr)+sizeof(struct tcphdr));
480 +
481 +               /*Build TCP header*/
482 +               ptr+=sizeof(struct sll_header)+ sizeof(struct iphdr);
483 +               tcph=(struct tcphdr*)ptr;
484 +               tcph->source=htons(1113);
485 +               tcph->dest=htons(1113);
486 +               tcph->doff=5;
487 +               tcph->check=htonl(0);
488 +               tcph->urg_ptr=0;
489 +               tcph->urg=0;
490 +               tcph->psh=0;
491 +               tcph->fin=1;
492 +               tcph->syn=0;
493 +               tcph->rst=0;
494 +               tcph->ack=1;
495 +
496 +               /*Adjust Sequence and Acknowledgment numbers and window*/
497 +               tcph->seq=htonl(state.ack_num++);
498 +               tcph->ack_seq=htonl(state.seq_num);
499 +               tcph->window=htons(WIN_FACTOR);
500 +
501 +               /*Save To Packet Capture*/
502 +               pcap_dump((u_char*)state.out,&nh, data);
503 +
504 +       /* 3)Create Ack Packet*/
505 +               /*make sure the packet is all zero*/
506 +               memset(data, 0, MAX_PACKET);
507 +               ptr=data;
508 +
509 +               /*Set the libpcap header*/
510 +               nh.caplen=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr);
511 +               nh.len=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr);
512 +               nh.ts.tv_usec+=1000; /*After the previous packet*/
513 +
514 +               /* Copy Ethernet and IP headers from private data area*/
515 +               /* These are headers from the first packet in the capture*/
516 +               memcpy(ptr, slip->od, sizeof(struct sll_header)+ sizeof(struct iphdr));
517 +
518 +               /*Update IP header*/
519 +               iph= (struct iphdr *) (ptr + sizeof(struct sll_header));
520 +               iph->protocol=6;
521 +               iph->check=htonl(0);
522 +               iph->tot_len=htons(sizeof(struct iphdr)+sizeof(struct tcphdr));
523 +
524 +               /*Build TCP header*/
525 +               ptr+=sizeof(struct ether_header)+ sizeof(struct iphdr);
526 +               tcph=(struct tcphdr*)ptr;
527 +               tcph->source=htons(1113);
528 +               tcph->dest=htons(1113);
529 +               tcph->doff=5;
530 +               tcph->check=htonl(0);
531 +               tcph->urg_ptr=0;
532 +               tcph->urg=0;
533 +               tcph->psh=0;
534 +               tcph->fin=0;
535 +               tcph->syn=0;
536 +               tcph->rst=0;
537 +               tcph->ack=1;
538 +
539 +               /*Adjust Sequence and Acknowledgment numbers and window*/
540 +               tcph->seq=htonl(state.seq_num++);
541 +               tcph->ack_seq=htonl(state.ack_num);
542 +               tcph->window=htons(WIN_FACTOR);
543 +
544 +               /*Save To Packet Capture*/
545 +               pcap_dump((u_char*)state.out,&nh, data);
546 +               return 0;
547 +}
548 +
549 +
550 +
551 +
552 +/* The UDP Encapsulation Structure*/
553 +struct encap_ops sll_encap = {
554 +       .pre=sll_encap_pre,
555 +       .post=sll_encap_post,
556 +};
557 diff -r ab54ffb0cb71 udp_encap.c
558 --- a/udp_encap.c       Fri Mar 04 11:30:16 2011 -0500
559 +++ b/udp_encap.c       Thu May 19 01:11:51 2011 -0400
560 @@ -15,13 +15,6 @@
561  
562  
563  
564 -/*UDP encapsulation private data structure*/
565 -struct udp_en_p{
566 -       struct pcap_pkthdr      header;
567 -       u_char                          od[sizeof(struct ether_header)+sizeof(struct iphdr)+sizeof(struct udphdr)];
568 -};
569 -
570 -
571  
572  /* encapsulation manipulation previous to packet conversion */
573  int udp_encap_pre(struct pcap_pkthdr *h, const u_char **odata, u_char **ndata, int* olength, int* nlength)