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
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
13 main.o: ltp2tcp.c ltp2tcp.h
14 gcc -c ${CFLAGS} ${LDLIBS} --std=gnu99 ltp2tcp.c -omain.o
16 dccp.o: dccp_encap.c encap.h ltp2tcp.h
17 gcc -c ${CFLAGS} ${LDLIBS} --std=gnu99 dccp_encap.c -odccp.o
19 +sll.o: sll_encap.c encap.h ltp2tcp.h
20 + gcc -c ${CFLAGS} ${LDLIBS} --std=gnu99 sll_encap.c -osll.o
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
29 state.en_ops=&dccp_encap;
32 + if(strcmp(string, "sll")==0 || strcmp(string,"SLL")==0){ /*SLL (Linux Cooked Capture)*/
33 + state.en_ops=&sll_encap;
36 printf("Encapsulation type: %s is not supported\n", string);
41 struct pcap_pkthdr nh;
43 - struct udp_en_p *uep;
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));
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
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;
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
70 +/******************************************************************************
75 +Description: <SLL, IPv4, UDP> encapsulation functions
77 +******************************************************************************/
79 +#include <pcap/sll.h>
80 +#include <netinet/udp.h>
86 +/*SLL encapsulation private data structure*/
89 + struct pcap_pkthdr header;
90 + u_char od[sizeof(struct sll_header)+sizeof(struct iphdr)+sizeof(struct udphdr)];
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){
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");
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));
109 + /* Just update the libpcap header (and associated timestamp)*/
110 + memcpy(&slip->header, h, sizeof(struct pcap_pkthdr));
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)
119 + struct sll_header *slh;
120 + struct udphdr *udph;
123 + if(!h || !odata || !ndata || !*odata || !*ndata || !olength || !nlength){
124 + dbgprintf(0,"Error: SLL Encapsulation given bad data!\n");
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");
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");
143 + if(fill_sllip4_encap((struct sll_en_p*)state.en_priv, *odata, *olength, h)<0){
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);
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");
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");
165 + if(iph->protocol!=0x11){
166 + dbgprintf(1, "Note: Packet is not UDP\n");
170 + /*set ip to indicate that tcp is next protocol*/
172 + iph->check=htonl(0);
174 + /* Adjust libpcap headers*/
175 + h->caplen=sizeof(struct sll_header) +sizeof(struct iphdr);
176 + h->len=sizeof(struct sll_header) +sizeof(struct iphdr);
178 + /*Adjust packet length*/
179 + udph=(struct udphdr*)*odata;
180 + *olength=ntohs(udph->len);
182 + /*Adjust New Packet Length*/
183 + *nlength-=sizeof(struct sll_header) +sizeof(struct iphdr);
185 + /*Move Packet Pointer past UDP header*/
186 + *odata+=sizeof(struct udphdr);
190 +/* encapsulation manipulation after conversion */
191 +int sll_encap_post(int tlen, u_char *data)
195 + /* Move data pointer to start of IPv4 header*/
196 + data+=sizeof(struct sll_header);
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");
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);
210 +/* Create a TCP three-way handshake */
211 +int sll_encap_handshake(struct pcap_pkthdr *h)
214 + struct tcphdr *tcph;
217 + struct pcap_pkthdr nh;
219 + struct sll_en_p *slip=(struct sll_en_p*)state.en_priv;
223 + if(h==NULL || state.en_priv==NULL){
224 + dbgprintf(1, "Error: SLL, IPv4 Encapsulation handshake method given bad data!\n");
228 + /*create new libpcap header*/
229 + memcpy(&nh, h, sizeof(struct pcap_pkthdr));
231 + /*create buffer for new packet*/
232 + ptr=data=malloc(MAX_PACKET);
234 + dbgprintf(0,"Error: Couldn't allocate Memory\n");
238 + /* 1)Create Syn Packet*/
239 + /*make sure the packet is all zero*/
240 + memset(data, 0, MAX_PACKET);
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*/
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));
252 + /*Adjust IP header*/
253 + iph= (struct iphdr *) (ptr + sizeof(struct sll_header));
255 + iph->check=htonl(0);
256 + iph->tot_len=htons(sizeof(struct iphdr)+sizeof(struct tcphdr)+4);
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);
264 + tcph->check=htonl(0);
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);
278 + /* Add SACK permitted option*/
279 + ptr+=sizeof(struct tcphdr);
284 + /*Save To Packet Capture*/
285 + pcap_dump((u_char*)state.out,&nh, data);
288 + /* 2)Create Syn,Ack Packet*/
289 + /*make sure the packet is all zero*/
290 + memset(data, 0, MAX_PACKET);
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*/
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));
302 + /*Adjust IP header, including swapping source and destination*/
303 + iph= (struct iphdr *) (ptr + sizeof(struct sll_header));
305 + iph->check=htonl(0);
307 + iph->saddr=iph->daddr;
309 + iph->tot_len=htons(sizeof(struct iphdr)+sizeof(struct tcphdr)+4);
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);
317 + tcph->check=htonl(0);
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);
331 + /* Add SACK permitted option*/
332 + ptr+=sizeof(struct tcphdr);
337 + /*Save To Packet Capture*/
338 + pcap_dump((u_char*)state.out,&nh, data);
340 + /* 3)Create Ack Packet*/
341 + /*make sure the packet is all zero*/
342 + memset(data, 0, MAX_PACKET);
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*/
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));
354 + /*Adjust IP header*/
355 + iph= (struct iphdr *) (ptr + sizeof(struct sll_header));
357 + iph->check=htonl(0);
358 + iph->tot_len=htons(sizeof(struct iphdr)+sizeof(struct tcphdr));
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);
366 + tcph->check=htonl(0);
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);
380 + /*Save To Packet Capture*/
381 + pcap_dump((u_char*)state.out,&nh, data);
385 +/* Create a TCP ending handshake */
389 + struct tcphdr *tcph;
392 + struct pcap_pkthdr nh;
394 + struct sll_en_p *slip=(struct sll_en_p*)state.en_priv;
398 + dbgprintf(1,"Error: SLL, IPv4 Encapsulation Finish method given invalid data!\n");
402 + /*copy the libpcap header from private data area*/
403 + memcpy(&nh, &slip->header, sizeof(struct pcap_pkthdr));
405 + /*create buffer for new packet*/
406 + ptr=data=malloc(MAX_PACKET);
408 + dbgprintf(0,"Error: Couldn't allocate Memory\n");
412 + /* 1)Create Fin Packet*/
413 + /*make sure the packet is all zero*/
414 + memset(data, 0, MAX_PACKET);
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*/
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));
426 + /*Adjust IP header*/
427 + iph= (struct iphdr *) (ptr + sizeof(struct sll_header));
429 + iph->check=htonl(0);
430 + iph->tot_len=htons(sizeof(struct iphdr)+sizeof(struct tcphdr));
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);
438 + tcph->check=htonl(0);
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);
452 + /*Update Sequence Number to include the fin packet in the sequence number space*/
455 + /* Save To Packet Capture*/
456 + pcap_dump((u_char*)state.out,&nh, data);
458 + /* 2)Create Fin,Ack Packet*/
459 + /*make sure the packet is all zero*/
460 + memset(data, 0, MAX_PACKET);
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*/
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));
472 + /*Update IP header, including swapping source and destination addresses*/
473 + iph= (struct iphdr *) (ptr + sizeof(struct sll_header));
475 + iph->check=htonl(0);
477 + iph->saddr=iph->daddr;
479 + iph->tot_len=htons(sizeof(struct iphdr)+sizeof(struct tcphdr));
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);
487 + tcph->check=htonl(0);
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);
501 + /*Save To Packet Capture*/
502 + pcap_dump((u_char*)state.out,&nh, data);
504 + /* 3)Create Ack Packet*/
505 + /*make sure the packet is all zero*/
506 + memset(data, 0, MAX_PACKET);
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*/
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));
518 + /*Update IP header*/
519 + iph= (struct iphdr *) (ptr + sizeof(struct sll_header));
521 + iph->check=htonl(0);
522 + iph->tot_len=htons(sizeof(struct iphdr)+sizeof(struct tcphdr));
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);
530 + tcph->check=htonl(0);
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);
544 + /*Save To Packet Capture*/
545 + pcap_dump((u_char*)state.out,&nh, data);
552 +/* The UDP Encapsulation Structure*/
553 +struct encap_ops sll_encap = {
554 + .pre=sll_encap_pre,
555 + .post=sll_encap_post,
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
564 -/*UDP encapsulation private data structure*/
566 - struct pcap_pkthdr header;
567 - u_char od[sizeof(struct ether_header)+sizeof(struct iphdr)+sizeof(struct udphdr)];
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)