annotate pcap/rtp-jitter-view.c @ 207:10f11a2d4042

pcap utils: fix bug in the case of RTP timestamp 16-bit rollover
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 17 Feb 2023 19:56:45 +0000
parents 693a0958a303
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program reads a pcap file, extracts packets belonging to a
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * particular RTP stream as identified by a source or destination
172
693a0958a303 yet another refactoring of RTP tools:
Mychaela Falconia <falcon@freecalypso.org>
parents: 171
diff changeset
4 * IP:port, checks its continuity at the packet header level
693a0958a303 yet another refactoring of RTP tools:
Mychaela Falconia <falcon@freecalypso.org>
parents: 171
diff changeset
5 * (verifies that the sequence number always increments by 1 and
693a0958a303 yet another refactoring of RTP tools:
Mychaela Falconia <falcon@freecalypso.org>
parents: 171
diff changeset
6 * that the timestamp always increments by 160 units) and prints out
171
75607bc26f57 rtp-cont-check design change: print time deltas instead of
Mychaela Falconia <falcon@freecalypso.org>
parents: 170
diff changeset
7 * the Rx time delta of each stream packet (the capture time of
75607bc26f57 rtp-cont-check design change: print time deltas instead of
Mychaela Falconia <falcon@freecalypso.org>
parents: 170
diff changeset
8 * the current packet minus the capture time of the previous packet)
172
693a0958a303 yet another refactoring of RTP tools:
Mychaela Falconia <falcon@freecalypso.org>
parents: 171
diff changeset
9 * on stdout, allowing visual analysis of timing jitter.
170
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
10 *
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
11 * The codec can be anything, and this program can also be used to
172
693a0958a303 yet another refactoring of RTP tools:
Mychaela Falconia <falcon@freecalypso.org>
parents: 171
diff changeset
12 * examine the jitter of RTP streams coming from PSTN/SIP, but the
170
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
13 * core assumption is that packets must arrive every 20 ms, with
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
14 * the timestamp field incrementing by 160 units each time.
15
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 */
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include <sys/types.h>
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include <sys/socket.h>
170
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
19 #include <sys/time.h>
15
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #include <netinet/in.h>
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include <arpa/inet.h>
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 #include <stdio.h>
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 #include <stdlib.h>
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 #include <string.h>
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 #include <strings.h>
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 #include <pcap/pcap.h>
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 static pcap_t *pcap;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 static in_addr_t match_ip_addr;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 static u_short match_udp_port;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 static unsigned iphdr_addr_offset, udphdr_port_offset;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 static unsigned link_hdr_len, ethertype_offset;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 static int stream_init_flag;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 static unsigned last_seq, last_tstamp, stream_ssrc;
170
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
35 static struct timeval last_pkt_time;
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
36
15
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 static void
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 check_dl_type()
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 int dltype;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 dltype = pcap_datalink(pcap);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 switch (dltype) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 case DLT_EN10MB:
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 link_hdr_len = 14;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 ethertype_offset = 12;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 break;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 case DLT_RAW:
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 link_hdr_len = 0;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 break;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 case DLT_LINUX_SLL:
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 link_hdr_len = 16;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 ethertype_offset = 14;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 break;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 default:
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 fprintf(stderr, "error: unsupported data link type %d\n",
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 dltype);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 static void
170
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
63 rtp_stream_logic(rtp_hdr, pkt_idx, pkt_time)
15
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 u_char *rtp_hdr;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 unsigned pkt_idx;
170
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
66 struct timeval *pkt_time;
15
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 unsigned cur_seq, cur_tstamp, cur_ssrc;
170
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
69 struct timeval deltat;
15
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 cur_seq = (rtp_hdr[2] << 8) | rtp_hdr[3];
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 cur_tstamp = (rtp_hdr[4] << 24) | (rtp_hdr[5] << 16) |
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 (rtp_hdr[6] << 8) | rtp_hdr[7];
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 cur_ssrc = (rtp_hdr[8] << 24) | (rtp_hdr[9] << 16) |
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 (rtp_hdr[10] << 8) | rtp_hdr[11];
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 if (stream_init_flag) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 if (cur_ssrc != stream_ssrc) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 fprintf(stderr,
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 "error in packet #%u: SSRC change from 0x%08X to 0x%08X\n",
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 pkt_idx, stream_ssrc, cur_ssrc);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 }
207
10f11a2d4042 pcap utils: fix bug in the case of RTP timestamp 16-bit rollover
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
83 if (cur_seq != last_seq + 1 &&
10f11a2d4042 pcap utils: fix bug in the case of RTP timestamp 16-bit rollover
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
84 (cur_seq != 0 || last_seq != 0xFFFF)) {
15
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 fprintf(stderr,
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 "error in packet #%u: seq break from 0x%04X to 0x%04X\n",
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 pkt_idx, last_seq, cur_seq);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 if (cur_tstamp != last_tstamp + 160) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 fprintf(stderr,
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 "error in packet #%u: timestamp break from 0x%08X to 0x%08X\n",
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 pkt_idx, last_tstamp, cur_tstamp);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 }
170
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
96 if (timercmp(pkt_time, &last_pkt_time, <)) {
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
97 fprintf(stderr,
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
98 "packet #%u timing error: Rx time goes backward\n",
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
99 pkt_idx);
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
100 exit(1);
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
101 }
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
102 timersub(pkt_time, &last_pkt_time, &deltat);
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
103 if (deltat.tv_sec) {
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
104 fprintf(stderr,
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
105 "packet #%u timing error: Rx time gap >= 1 s\n",
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
106 pkt_idx);
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
107 exit(1);
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
108 }
171
75607bc26f57 rtp-cont-check design change: print time deltas instead of
Mychaela Falconia <falcon@freecalypso.org>
parents: 170
diff changeset
109 printf("Packet #%u: time delta %u us\n", pkt_idx,
75607bc26f57 rtp-cont-check design change: print time deltas instead of
Mychaela Falconia <falcon@freecalypso.org>
parents: 170
diff changeset
110 (unsigned) deltat.tv_usec);
15
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 } else {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 stream_init_flag = 1;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 stream_ssrc = cur_ssrc;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 last_seq = cur_seq;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 last_tstamp = cur_tstamp;
170
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
117 bcopy(pkt_time, &last_pkt_time, sizeof(struct timeval));
15
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 static void
170
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
121 process_packet(pkt, caplen, pkt_idx, pkt_time)
15
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 u_char *pkt;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 unsigned caplen, pkt_idx;
170
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
124 struct timeval *pkt_time;
15
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 {
170
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
126 unsigned udplen;
15
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 if (caplen < link_hdr_len + 28)
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 return;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 if (link_hdr_len) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 if (pkt[ethertype_offset] != 0x08)
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 return;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 if (pkt[ethertype_offset+1] != 0x00)
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 return;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 pkt += link_hdr_len;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 caplen -= link_hdr_len;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 /* check IP header */
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 if (pkt[0] != 0x45)
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 return;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 if (pkt[9] != 17) /* UDP */
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 return;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 if (bcmp(pkt + iphdr_addr_offset, &match_ip_addr, 4))
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 return;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 /* check UDP header */
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 if (bcmp(pkt + 20 + udphdr_port_offset, &match_udp_port, 2))
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 return;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 /* it is our target - now scrutinize it */
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 udplen = (pkt[24] << 8) | pkt[25];
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 if (caplen < udplen + 20) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 fprintf(stderr,
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 "error: packet #%u is truncated in the capture\n",
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 pkt_idx);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 if (udplen < 20) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 fprintf(stderr,
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 "error in packet #%u: UDP length is too short for RTP header\n",
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 pkt_idx);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 if (pkt[28] != 0x80) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 fprintf(stderr,
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 "error in packet #%u: unsupported RTP header structure\n",
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 pkt_idx);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 }
170
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
168 rtp_stream_logic(pkt + 28, pkt_idx, pkt_time);
15
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 main(argc, argv)
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 char **argv;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 char errbuf[PCAP_ERRBUF_SIZE];
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 u_char *pkt;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 struct pcap_pkthdr pkthdr;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 unsigned pkt_idx;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178
170
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
179 if (argc != 5) {
15
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 fprintf(stderr,
170
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
181 "usage: %s pcap-file src|dest ip-addr udp-port\n",
15
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 argv[0]);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 pcap = pcap_open_offline(argv[1], errbuf);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 if (!pcap) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 fprintf(stderr, "%s: %s\n", argv[1], errbuf);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 check_dl_type();
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 if (!strcmp(argv[2], "src")) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 iphdr_addr_offset = 12;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 udphdr_port_offset = 0;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 } else if (!strcmp(argv[2], "dest")) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 iphdr_addr_offset = 16;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 udphdr_port_offset = 2;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 } else {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 fprintf(stderr,
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 "error: direction argument must be \"src\" or \"dest\"\n");
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 match_ip_addr = inet_addr(argv[3]);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 if (match_ip_addr == INADDR_NONE) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 fprintf(stderr, "error: IP address argument is invalid\n");
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 match_udp_port = htons(strtoul(argv[4], 0, 0));
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 for (pkt_idx = 0; ; pkt_idx++) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 pkt = pcap_next(pcap, &pkthdr);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 if (!pkt)
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 break;
170
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
212 process_packet(pkt, (unsigned) pkthdr.caplen, pkt_idx,
b9af126bfddb rtp-cont-check utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
213 &pkthdr.ts);
15
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 if (!stream_init_flag) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 fprintf(stderr, "error: specified RTP stream not found\n");
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 exit(0);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 }