1 | #include <stdio.h> |
---|
2 | #include <assert.h> |
---|
3 | #include "libtrace.h" |
---|
4 | #include <map> |
---|
5 | |
---|
6 | uint64_t with_ts[4][65536]; |
---|
7 | uint64_t without_ts[4][65536]; |
---|
8 | |
---|
9 | struct libtrace_packet_t packet; |
---|
10 | |
---|
11 | /** parse an option |
---|
12 | * @param ptr the pointer to the current option |
---|
13 | * @param plen the length of the remaining buffer |
---|
14 | * @param type the type of the option |
---|
15 | * @param optlen the length of the option |
---|
16 | * @param data the data of the option |
---|
17 | * |
---|
18 | * @returns bool true if there is another option (and the fields are filled in) |
---|
19 | */ |
---|
20 | int get_next_option(unsigned char **ptr,int *len, |
---|
21 | unsigned char *type, |
---|
22 | unsigned char *optlen, |
---|
23 | unsigned char **data) |
---|
24 | { |
---|
25 | if (*len<=0) { |
---|
26 | // printf("Missing End of Options\n"); |
---|
27 | return 0; |
---|
28 | } |
---|
29 | *type=**ptr; |
---|
30 | switch(*type) { |
---|
31 | case 0: /* End of options */ |
---|
32 | // printf("End of option\n"); |
---|
33 | return 0; |
---|
34 | case 1: /* Pad */ |
---|
35 | (*ptr)++; |
---|
36 | (*len)--; |
---|
37 | return 1; |
---|
38 | default: |
---|
39 | case 6: // ECHO (obsolete) |
---|
40 | case 7: // ECHO Reply (obsolete) |
---|
41 | case 9: // Partial ordering |
---|
42 | case 10: // Partial ordering service profile |
---|
43 | case 11: // CC |
---|
44 | case 13: // CC.ECHO |
---|
45 | case 14: // Alternative checksum request |
---|
46 | case 15: // Alternative checksum data |
---|
47 | case 16: // Skeeter |
---|
48 | case 17: // Bubba |
---|
49 | case 18: // Trailer checksum |
---|
50 | case 19: // Md5 signature |
---|
51 | case 20: // SCPS capability |
---|
52 | case 21: // Selective NACK |
---|
53 | case 22: // Record boundary |
---|
54 | case 23: // Corruption experienced |
---|
55 | case 24: // SNAP |
---|
56 | case 25: // Unassigned |
---|
57 | case 26: // TCP Compression filter |
---|
58 | printf("Unknown option type (%i)\n",*type); |
---|
59 | case 2: // MSS |
---|
60 | case 3: // WS |
---|
61 | case 4: // SACK permitted |
---|
62 | case 5: // SACK |
---|
63 | case 8: // Timestamp |
---|
64 | case 12: // CC.new |
---|
65 | *optlen = *(*ptr+1); |
---|
66 | if (*optlen<2) { |
---|
67 | printf("Optlen <2?! %i\n",*optlen); |
---|
68 | return 0; // I have no idea wtf is going on |
---|
69 | // with these packets |
---|
70 | } |
---|
71 | (*len)-=(unsigned int)*optlen; |
---|
72 | (*data)=(*ptr+2); |
---|
73 | (*ptr)+=*optlen; |
---|
74 | if (*len<0) { |
---|
75 | printf("Option longer than option area (%i > %i)\n",*optlen,*len+*optlen); |
---|
76 | return 0; |
---|
77 | } |
---|
78 | return 1; |
---|
79 | } |
---|
80 | assert(0); |
---|
81 | } |
---|
82 | |
---|
83 | int main(int argc, char *argv[]) |
---|
84 | { |
---|
85 | struct libtrace_t *trace; |
---|
86 | double last = 0; |
---|
87 | |
---|
88 | trace = trace_create(argv[1]); |
---|
89 | |
---|
90 | for (;;) { |
---|
91 | int psize; |
---|
92 | |
---|
93 | if ((psize = trace_read_packet(trace, &packet)) <= 0) { |
---|
94 | break; |
---|
95 | } |
---|
96 | |
---|
97 | struct libtrace_ip *ipptr = trace_get_ip(&packet); |
---|
98 | |
---|
99 | if (!ipptr) |
---|
100 | continue; |
---|
101 | |
---|
102 | if (ipptr->ip_hl!=5) { |
---|
103 | printf("*"); |
---|
104 | fflush(stdout); |
---|
105 | } |
---|
106 | |
---|
107 | double now=trace_get_seconds(&packet); |
---|
108 | |
---|
109 | if (now-last>60) { |
---|
110 | printf("."); |
---|
111 | fflush(stdout); |
---|
112 | last=now; |
---|
113 | } |
---|
114 | |
---|
115 | } |
---|
116 | |
---|
117 | return 0; |
---|
118 | } |
---|