annotate pcap-study/rtp-stream-dump.c @ 16:1bc144545563

pcap-study: new program rtp-tw5-extr
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 10 Oct 2024 17:40:16 +0000
parents e7f43262efa1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
6
709aa9ad72d1 new program rtp-stream-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
2 * This program is an aid for analyzing arbitrary RTP streams:
709aa9ad72d1 new program rtp-stream-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
3 * it reads a pcap file, extracts packets belonging to a particular
709aa9ad72d1 new program rtp-stream-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
4 * RTP stream as identified by a source or destination IP:port,
709aa9ad72d1 new program rtp-stream-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
5 * and displays a one-line summary of every RTP packet.
709aa9ad72d1 new program rtp-stream-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
6 * Discontinuities are treated as non-fatal errors: an error message
709aa9ad72d1 new program rtp-stream-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
7 * is printed, but analysis continues.
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 */
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <sys/types.h>
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <sys/socket.h>
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <netinet/in.h>
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <arpa/inet.h>
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <stdio.h>
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <stdlib.h>
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include <string.h>
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include <strings.h>
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include <pcap/pcap.h>
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 static pcap_t *pcap;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 static in_addr_t match_ip_addr;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 static u_short match_udp_port;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 static unsigned iphdr_addr_offset, udphdr_port_offset;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 static unsigned link_hdr_len, ethertype_offset;
13
d59dbdfe1778 rtp-stream-dump: compute and print time-of-arrival delta (toad)
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
25 static int stream_init_flag, toad_init_flag;
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 static unsigned last_seq, last_tstamp, stream_ssrc;
13
d59dbdfe1778 rtp-stream-dump: compute and print time-of-arrival delta (toad)
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
27 static struct timeval last_pkt_time;
14
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
28 static int do_hexdump;
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 static void
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 check_dl_type()
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 int dltype;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 dltype = pcap_datalink(pcap);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 switch (dltype) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 case DLT_EN10MB:
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 link_hdr_len = 14;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 ethertype_offset = 12;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 break;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 case DLT_RAW:
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 link_hdr_len = 0;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 break;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 case DLT_LINUX_SLL:
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 link_hdr_len = 16;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 ethertype_offset = 14;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 break;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 default:
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 fprintf(stderr, "error: unsupported data link type %d\n",
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 dltype);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 exit(1);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 static void
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 rtp_stream_logic(rtp_hdr, pkt_idx)
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 u_char *rtp_hdr;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 unsigned pkt_idx;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 unsigned cur_seq, cur_tstamp, cur_ssrc;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 cur_seq = (rtp_hdr[2] << 8) | rtp_hdr[3];
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 cur_tstamp = (rtp_hdr[4] << 24) | (rtp_hdr[5] << 16) |
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 (rtp_hdr[6] << 8) | rtp_hdr[7];
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 cur_ssrc = (rtp_hdr[8] << 24) | (rtp_hdr[9] << 16) |
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 (rtp_hdr[10] << 8) | rtp_hdr[11];
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 if (stream_init_flag) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 if (cur_ssrc != stream_ssrc) {
5
7c85a7a913f7 rtp-gsmfr-dump: treat stream discontinuities as non-fatal
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
69 printf(
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 "error in packet #%u: SSRC change from 0x%08X to 0x%08X\n",
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 pkt_idx, stream_ssrc, cur_ssrc);
5
7c85a7a913f7 rtp-gsmfr-dump: treat stream discontinuities as non-fatal
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
72 } else if (cur_seq != last_seq + 1 &&
7c85a7a913f7 rtp-gsmfr-dump: treat stream discontinuities as non-fatal
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
73 (cur_seq != 0 || last_seq != 0xFFFF)) {
7c85a7a913f7 rtp-gsmfr-dump: treat stream discontinuities as non-fatal
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
74 printf(
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 "error in packet #%u: seq break from 0x%04X to 0x%04X\n",
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 pkt_idx, last_seq, cur_seq);
5
7c85a7a913f7 rtp-gsmfr-dump: treat stream discontinuities as non-fatal
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
77 } else if (cur_tstamp != last_tstamp + 160) {
7c85a7a913f7 rtp-gsmfr-dump: treat stream discontinuities as non-fatal
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
78 printf(
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 "error in packet #%u: timestamp break from 0x%08X to 0x%08X\n",
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 pkt_idx, last_tstamp, cur_tstamp);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 }
5
7c85a7a913f7 rtp-gsmfr-dump: treat stream discontinuities as non-fatal
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
82 } else
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 stream_init_flag = 1;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 last_seq = cur_seq;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 last_tstamp = cur_tstamp;
5
7c85a7a913f7 rtp-gsmfr-dump: treat stream discontinuities as non-fatal
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
86 stream_ssrc = cur_ssrc;
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 static void
14
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
90 hexdump_payload(payload, payload_len)
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
91 u_char *payload;
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
92 unsigned payload_len;
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
93 {
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
94 unsigned off;
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
95
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
96 for (off = 0; off < payload_len; off++) {
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
97 if ((off & 3) == 0)
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
98 putchar(' ');
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
99 printf(" %02X", payload[off]);
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
100 if ((off & 15) == 15 || off == payload_len - 1)
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
101 putchar('\n');
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
102 }
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
103 }
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
104
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
105 static void
13
d59dbdfe1778 rtp-stream-dump: compute and print time-of-arrival delta (toad)
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
106 process_packet(pkt, caplen, pkt_idx, pkt_time)
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 u_char *pkt;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 unsigned caplen, pkt_idx;
13
d59dbdfe1778 rtp-stream-dump: compute and print time-of-arrival delta (toad)
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
109 struct timeval *pkt_time;
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 unsigned udplen, payload_len;
13
d59dbdfe1778 rtp-stream-dump: compute and print time-of-arrival delta (toad)
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
112 struct timeval toad;
d59dbdfe1778 rtp-stream-dump: compute and print time-of-arrival delta (toad)
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
113 unsigned toad_ms, toad_us;
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 if (caplen < link_hdr_len + 28)
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 return;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 if (link_hdr_len) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 if (pkt[ethertype_offset] != 0x08)
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 return;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 if (pkt[ethertype_offset+1] != 0x00)
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 return;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 pkt += link_hdr_len;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 caplen -= link_hdr_len;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 /* check IP header */
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 if (pkt[0] != 0x45)
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 return;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 if (pkt[9] != 17) /* UDP */
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 return;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 if (bcmp(pkt + iphdr_addr_offset, &match_ip_addr, 4))
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 return;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 /* check UDP header */
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 if (bcmp(pkt + 20 + udphdr_port_offset, &match_udp_port, 2))
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 return;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 /* it is our target - now scrutinize it */
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 udplen = (pkt[24] << 8) | pkt[25];
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 if (caplen < udplen + 20) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 fprintf(stderr,
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 "error: packet #%u is truncated in the capture\n",
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 pkt_idx);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 exit(1);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 if (udplen < 20) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 fprintf(stderr,
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 "error in packet #%u: UDP length is too short for RTP header\n",
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 pkt_idx);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 exit(1);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 if (pkt[28] != 0x80) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 fprintf(stderr,
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 "error in packet #%u: unsupported RTP header structure\n",
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 pkt_idx);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 exit(1);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 rtp_stream_logic(pkt + 28, pkt_idx);
14
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
156 payload_len = udplen - 20;
13
d59dbdfe1778 rtp-stream-dump: compute and print time-of-arrival delta (toad)
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
157 printf("pkt #%u seq 0x%04X ts 0x%08X: pt=%u M=%u len=%u", pkt_idx,
6
709aa9ad72d1 new program rtp-stream-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
158 last_seq, last_tstamp, pkt[29] & 0x7F, pkt[29] >> 7,
14
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
159 payload_len);
13
d59dbdfe1778 rtp-stream-dump: compute and print time-of-arrival delta (toad)
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
160 if (toad_init_flag && timercmp(pkt_time, &last_pkt_time, >=)) {
d59dbdfe1778 rtp-stream-dump: compute and print time-of-arrival delta (toad)
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
161 timersub(pkt_time, &last_pkt_time, &toad);
d59dbdfe1778 rtp-stream-dump: compute and print time-of-arrival delta (toad)
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
162 if (toad.tv_sec)
d59dbdfe1778 rtp-stream-dump: compute and print time-of-arrival delta (toad)
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
163 printf(", toad %u.%06u s", (unsigned) toad.tv_sec,
d59dbdfe1778 rtp-stream-dump: compute and print time-of-arrival delta (toad)
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
164 (unsigned) toad.tv_usec);
d59dbdfe1778 rtp-stream-dump: compute and print time-of-arrival delta (toad)
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
165 else {
d59dbdfe1778 rtp-stream-dump: compute and print time-of-arrival delta (toad)
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
166 toad_ms = toad.tv_usec / 1000;
d59dbdfe1778 rtp-stream-dump: compute and print time-of-arrival delta (toad)
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
167 toad_us = toad.tv_usec % 1000;
d59dbdfe1778 rtp-stream-dump: compute and print time-of-arrival delta (toad)
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
168 printf(", toad %u.%03u ms", toad_ms, toad_us);
d59dbdfe1778 rtp-stream-dump: compute and print time-of-arrival delta (toad)
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
169 }
d59dbdfe1778 rtp-stream-dump: compute and print time-of-arrival delta (toad)
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
170 }
d59dbdfe1778 rtp-stream-dump: compute and print time-of-arrival delta (toad)
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
171 putchar('\n');
14
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
172 if (do_hexdump)
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
173 hexdump_payload(pkt + 40, payload_len);
13
d59dbdfe1778 rtp-stream-dump: compute and print time-of-arrival delta (toad)
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
174 bcopy(pkt_time, &last_pkt_time, sizeof(struct timeval));
d59dbdfe1778 rtp-stream-dump: compute and print time-of-arrival delta (toad)
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
175 toad_init_flag = 1;
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 main(argc, argv)
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 char **argv;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 char errbuf[PCAP_ERRBUF_SIZE];
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 u_char *pkt;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 struct pcap_pkthdr pkthdr;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 unsigned pkt_idx;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185
14
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
186 switch (argc) {
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
187 case 5:
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
188 do_hexdump = 0;
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
189 break;
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
190 case 6:
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
191 if (strcmp(argv[5], "hex"))
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
192 goto usage;
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
193 do_hexdump = 1;
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
194 break;
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
195 default:
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
196 usage:
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 fprintf(stderr,
14
e7f43262efa1 rtp-stream-dump: add hex dump option
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
198 "usage: %s pcap-file src|dest ip-addr udp-port [hex]\n",
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 argv[0]);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 exit(1);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 pcap = pcap_open_offline(argv[1], errbuf);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 if (!pcap) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 fprintf(stderr, "%s: %s\n", argv[1], errbuf);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 exit(1);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 check_dl_type();
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 if (!strcmp(argv[2], "src")) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 iphdr_addr_offset = 12;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 udphdr_port_offset = 0;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 } else if (!strcmp(argv[2], "dest")) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 iphdr_addr_offset = 16;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 udphdr_port_offset = 2;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 } else {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 fprintf(stderr,
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 "error: direction argument must be \"src\" or \"dest\"\n");
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 exit(1);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 match_ip_addr = inet_addr(argv[3]);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 if (match_ip_addr == INADDR_NONE) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 fprintf(stderr, "error: IP address argument is invalid\n");
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 exit(1);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 match_udp_port = htons(strtoul(argv[4], 0, 0));
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 for (pkt_idx = 0; ; pkt_idx++) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 pkt = pcap_next(pcap, &pkthdr);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 if (!pkt)
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 break;
13
d59dbdfe1778 rtp-stream-dump: compute and print time-of-arrival delta (toad)
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
229 process_packet(pkt, (unsigned) pkthdr.caplen, pkt_idx,
d59dbdfe1778 rtp-stream-dump: compute and print time-of-arrival delta (toad)
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
230 &pkthdr.ts);
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 if (!stream_init_flag) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 fprintf(stderr, "error: specified RTP stream not found\n");
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 exit(1);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 exit(0);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 }