FreeCalypso > hg > rtp-debug-utils
annotate rtp-tfo-trace.c @ 1:41eba040785a
rtp-tfo-trace program written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 02 Apr 2023 05:36:35 +0000 |
parents | |
children |
rev | line source |
---|---|
1
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This program reads a pcap file containing RTP packets of a PSTN call |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * (PCMU or PCMA, 160 samples per RTP packet), flowing in one or both |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * directions, and looks for TFO IS messages. |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/types.h> |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <sys/socket.h> |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <netinet/in.h> |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <arpa/inet.h> |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdio.h> |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdlib.h> |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <string.h> |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <strings.h> |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include <pcap/pcap.h> |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 static pcap_t *pcap; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 static in_addr_t match_ip_addr; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 static u_short match_udp_port; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 static unsigned link_hdr_len, ethertype_offset; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 static struct onedir { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 int init_flag; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 unsigned last_seq; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 unsigned last_tstamp; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 unsigned stream_ssrc; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 u_char is_hunt_buf[320]; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 int is_state; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 unsigned is_hunt_fill; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 unsigned is_offset; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 unsigned is_alignment; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 unsigned is_bit_count; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 unsigned is_rx_word; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 } rx_state, tx_state; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 static const u_char hdr_pattern[20] = {0, 1, 0, 1, 0, 1, 1, 0, 1, 0, |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 0, 1, 1, 0, 1, 0, 1, 0, 0, 1}; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 static void |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 check_dl_type() |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 int dltype; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 dltype = pcap_datalink(pcap); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 switch (dltype) { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 case DLT_EN10MB: |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 link_hdr_len = 14; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 ethertype_offset = 12; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 break; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 case DLT_RAW: |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 link_hdr_len = 0; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 break; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 case DLT_LINUX_SLL: |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 link_hdr_len = 16; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 ethertype_offset = 14; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 break; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 default: |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 fprintf(stderr, "error: unsupported data link type %d\n", |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 dltype); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 exit(1); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 static void |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 rtp_stream_logic(rtp_hdr, pkt_idx, st, dir_str) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 u_char *rtp_hdr; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 unsigned pkt_idx; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 struct onedir *st; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 char *dir_str; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 unsigned cur_seq, cur_tstamp, cur_ssrc; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 cur_seq = (rtp_hdr[2] << 8) | rtp_hdr[3]; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 cur_tstamp = (rtp_hdr[4] << 24) | (rtp_hdr[5] << 16) | |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 (rtp_hdr[6] << 8) | rtp_hdr[7]; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 cur_ssrc = (rtp_hdr[8] << 24) | (rtp_hdr[9] << 16) | |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 (rtp_hdr[10] << 8) | rtp_hdr[11]; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 if (st->init_flag) { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 if (cur_ssrc != st->stream_ssrc) { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 printf( |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 "error in %s packet #%u: SSRC change from 0x%08X to 0x%08X\n", |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 dir_str, pkt_idx, st->stream_ssrc, cur_ssrc); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 } else if (cur_seq != st->last_seq + 1 && |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 (cur_seq != 0 || st->last_seq != 0xFFFF)) { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 printf( |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 "error in %s packet #%u: seq break from 0x%04X to 0x%04X\n", |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 dir_str, pkt_idx, st->last_seq, cur_seq); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 } else if (cur_tstamp != st->last_tstamp + 160) { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 printf( |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 "error in %s packet #%u: timestamp break from 0x%08X to 0x%08X\n", |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 dir_str, pkt_idx, st->last_tstamp, cur_tstamp); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 } else |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 st->init_flag = 1; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 st->last_seq = cur_seq; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 st->last_tstamp = cur_tstamp; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 st->stream_ssrc = cur_ssrc; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 static void |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 is_rx_hunt(input_pos, pkt_idx, st, dir_str) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 unsigned input_pos; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 unsigned pkt_idx; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 struct onedir *st; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 char *dir_str; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 unsigned offset, n; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 for (offset = 0; offset < 16; offset++) { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 for (n = 0; n < 20; n++) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 if ((st->is_hunt_buf[offset + n*16] & 1) != |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 hdr_pattern[n]) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 break; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 if (n == 20) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 break; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 if (n != 20) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 return; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 st->is_offset = offset; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 st->is_alignment = input_pos * 16 + offset; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 st->is_state = 1; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 st->is_bit_count = 0; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 st->is_rx_word = 0; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 st->is_hunt_fill = 0; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 static void |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 is_process_cmd(pkt_idx, st, dir_str) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 unsigned pkt_idx; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 struct onedir *st; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 char *dir_str; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 int cont; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 printf("#%u: %s (align %u) ", pkt_idx, dir_str, st->is_alignment); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 switch (st->is_rx_word) { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 case 0x05D: |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 printf("IS_REQ\n"); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 cont = 1; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 break; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 case 0x0BA: |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 printf("IS_ACK\n"); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 cont = 1; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 break; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 case 0x0E7: |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 printf("IS_IPE\n"); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 cont = 1; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 break; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 case 0x129: |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 printf("IS_FILL\n"); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 cont = 0; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 break; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 case 0x174: |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 printf("IS_DUP\n"); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 cont = 0; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 break; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 case 0x193: |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 printf("IS_SYL\n"); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 cont = 0; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 break; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 default: |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 printf("Unknown IS_Command 0x%03X\n", st->is_rx_word); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 cont = 0; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 if (cont) { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 st->is_state = 2; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 st->is_bit_count = 0; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 st->is_rx_word = 0; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 } else |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 st->is_state = 0; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 static void |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 is_process_ext(pkt_idx, st, dir_str) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 unsigned pkt_idx; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 struct onedir *st; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 char *dir_str; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 printf("#%u: %s IS_Extension: 0x%05X", pkt_idx, dir_str, |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 st->is_rx_word); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 if (st->is_rx_word & 0x80200) { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 printf(" (bad sync)\n"); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 st->is_state = 0; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 return; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 switch (st->is_rx_word & 3) { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 case 0: |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 printf(" (final)\n"); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 st->is_state = 0; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 return; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 case 3: |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 printf(" (continue)\n"); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 st->is_state = 2; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 st->is_bit_count = 0; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 st->is_rx_word = 0; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 return; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 default: |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 printf(" (bad EX)\n"); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 st->is_state = 0; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 static void |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 is_rx_process(input, input_pos, pkt_idx, st, dir_str) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 uint8_t *input; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 unsigned input_pos; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 unsigned pkt_idx; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 struct onedir *st; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 char *dir_str; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 unsigned new_bit; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 memmove(st->is_hunt_buf, st->is_hunt_buf + 16, 304); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 memcpy(st->is_hunt_buf + 304, input, 16); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 if (!st->is_state) { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 if (st->is_hunt_fill < 20) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 st->is_hunt_fill++; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 if (st->is_hunt_fill == 20) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 is_rx_hunt(input_pos, pkt_idx, st, dir_str); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 return; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 new_bit = input[st->is_offset] & 1; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 st->is_rx_word <<= 1; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 st->is_rx_word |= new_bit; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 st->is_bit_count++; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 if (st->is_state == 1 && st->is_bit_count == 10) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 is_process_cmd(pkt_idx, st, dir_str); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 else if (st->is_state == 2 && st->is_bit_count == 20) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 is_process_ext(pkt_idx, st, dir_str); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 static void |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 process_packet_onedir(pkt, caplen, pkt_idx, st, dir_str) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 u_char *pkt; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
235 unsigned caplen, pkt_idx; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 struct onedir *st; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 char *dir_str; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
238 { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
239 unsigned udplen, payload_len; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
240 unsigned is_chunk; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
241 |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
242 udplen = (pkt[24] << 8) | pkt[25]; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
243 if (caplen < udplen + 20) { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
244 printf("error: %s packet #%u is truncated in the capture\n", |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
245 dir_str, pkt_idx); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
246 return; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
247 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
248 if (udplen < 20) { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
249 printf( |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
250 "error in %s packet #%u: UDP length is too short for RTP header\n", |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
251 dir_str, pkt_idx); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
252 return; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
253 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
254 if (pkt[28] != 0x80) { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
255 printf( |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
256 "error in %s packet #%u: unsupported RTP header structure\n", |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
257 dir_str, pkt_idx); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
258 return; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
259 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
260 rtp_stream_logic(pkt + 28, pkt_idx, st, dir_str); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
261 payload_len = udplen - 20; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
262 if (payload_len != 160) { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
263 printf("error in %s packet #%u: wrong payload length\n", |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
264 dir_str, pkt_idx); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
265 return; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
266 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
267 for (is_chunk = 0; is_chunk < 10; is_chunk++) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
268 is_rx_process(pkt + 40 + is_chunk * 16, is_chunk, pkt_idx, st, |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
269 dir_str); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
270 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
271 |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
272 static void |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
273 process_packet(pkt, caplen, pkt_idx) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
274 u_char *pkt; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
275 unsigned caplen, pkt_idx; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
276 { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
277 if (caplen < link_hdr_len + 28) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
278 return; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
279 if (link_hdr_len) { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
280 if (pkt[ethertype_offset] != 0x08) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
281 return; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
282 if (pkt[ethertype_offset+1] != 0x00) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
283 return; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
284 pkt += link_hdr_len; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
285 caplen -= link_hdr_len; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
286 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
287 /* check IP header */ |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
288 if (pkt[0] != 0x45) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
289 return; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
290 if (pkt[9] != 17) /* UDP */ |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
291 return; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
292 if (!bcmp(pkt + 12, &match_ip_addr, 4) && |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
293 !bcmp(pkt + 20, &match_udp_port, 2)) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
294 process_packet_onedir(pkt, caplen, pkt_idx, &tx_state, "-->"); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
295 else if (!bcmp(pkt + 16, &match_ip_addr, 4) && |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
296 !bcmp(pkt + 22, &match_udp_port, 2)) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
297 process_packet_onedir(pkt, caplen, pkt_idx, &rx_state, "<--"); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
298 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
299 |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
300 main(argc, argv) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
301 char **argv; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
302 { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
303 char errbuf[PCAP_ERRBUF_SIZE]; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
304 u_char *pkt; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
305 struct pcap_pkthdr pkthdr; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
306 unsigned pkt_idx; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
307 |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
308 if (argc != 4) { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
309 fprintf(stderr, "usage: %s pcap-file ip-addr udp-port\n", |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
310 argv[0]); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
311 exit(1); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
312 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
313 pcap = pcap_open_offline(argv[1], errbuf); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
314 if (!pcap) { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
315 fprintf(stderr, "%s: %s\n", argv[1], errbuf); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
316 exit(1); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
317 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
318 check_dl_type(); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
319 match_ip_addr = inet_addr(argv[2]); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
320 if (match_ip_addr == INADDR_NONE) { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
321 fprintf(stderr, "error: IP address argument is invalid\n"); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
322 exit(1); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
323 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
324 match_udp_port = htons(strtoul(argv[3], 0, 0)); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
325 for (pkt_idx = 0; ; pkt_idx++) { |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
326 pkt = pcap_next(pcap, &pkthdr); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
327 if (!pkt) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
328 break; |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
329 process_packet(pkt, (unsigned) pkthdr.caplen, pkt_idx); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
330 } |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
331 if (!tx_state.init_flag) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
332 printf( |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
333 "Warning: found no packets with src matching specified IP:port\n"); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
334 if (!rx_state.init_flag) |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
335 printf( |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
336 "Warning: found no packets with dest matching specified IP:port\n"); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
337 exit(0); |
41eba040785a
rtp-tfo-trace program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
338 } |