annotate pcap/rtp-gsmfr-extr.c @ 20:93ed41fb4038

libgsmfrp/Makefile: add install
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 20 Nov 2022 06:36:09 +0000
parents 851ca64e38e9
children 10f11a2d4042
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
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * IP:port, verifies that an unbroken RTP stream is present, in
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * GSM FR or EFR codec, and writes the FR/EFR frame stream to our
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * extended-libgsm format binary file, to be fed to decoding test
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 * programs.
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 */
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <sys/types.h>
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <sys/socket.h>
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <netinet/in.h>
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <arpa/inet.h>
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <stdio.h>
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <stdlib.h>
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include <string.h>
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include <strings.h>
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include <pcap/pcap.h>
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 static pcap_t *pcap;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 static in_addr_t match_ip_addr;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 static u_short match_udp_port;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 static unsigned iphdr_addr_offset, udphdr_port_offset;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 static unsigned link_hdr_len, ethertype_offset;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 static FILE *outfile;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 static int stream_init_flag;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 static unsigned last_seq, last_tstamp, stream_ssrc;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 static void
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 check_dl_type()
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 int dltype;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 dltype = pcap_datalink(pcap);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 switch (dltype) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 case DLT_EN10MB:
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 link_hdr_len = 14;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 ethertype_offset = 12;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 break;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 case DLT_RAW:
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 link_hdr_len = 0;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 break;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 case DLT_LINUX_SLL:
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 link_hdr_len = 16;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 ethertype_offset = 14;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 break;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 default:
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 fprintf(stderr, "error: unsupported data link type %d\n",
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 dltype);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 static void
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 rtp_stream_logic(rtp_hdr, pkt_idx)
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 u_char *rtp_hdr;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 unsigned pkt_idx;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 unsigned cur_seq, cur_tstamp, cur_ssrc;
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 cur_seq = (rtp_hdr[2] << 8) | rtp_hdr[3];
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 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
63 (rtp_hdr[6] << 8) | rtp_hdr[7];
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 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
65 (rtp_hdr[10] << 8) | rtp_hdr[11];
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 if (stream_init_flag) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 if (cur_ssrc != stream_ssrc) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 fprintf(stderr,
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 "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
70 pkt_idx, stream_ssrc, cur_ssrc);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 if (cur_seq != last_seq + 1) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 fprintf(stderr,
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 "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
76 pkt_idx, last_seq, cur_seq);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 if (cur_tstamp != last_tstamp + 160) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 fprintf(stderr,
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 "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
82 pkt_idx, last_tstamp, cur_tstamp);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 } else {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 stream_init_flag = 1;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 stream_ssrc = cur_ssrc;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 last_seq = cur_seq;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 last_tstamp = cur_tstamp;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 static void
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 process_packet(pkt, caplen, pkt_idx)
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 u_char *pkt;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 unsigned caplen, pkt_idx;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 unsigned udplen, payload_len;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 if (caplen < link_hdr_len + 28)
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 return;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 if (link_hdr_len) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 if (pkt[ethertype_offset] != 0x08)
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 return;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 if (pkt[ethertype_offset+1] != 0x00)
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 return;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 pkt += link_hdr_len;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 caplen -= link_hdr_len;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 /* check IP header */
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 if (pkt[0] != 0x45)
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 return;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 if (pkt[9] != 17) /* UDP */
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 return;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 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
116 return;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 /* check UDP header */
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 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
119 return;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 /* it is our target - now scrutinize it */
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 udplen = (pkt[24] << 8) | pkt[25];
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 if (caplen < udplen + 20) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 fprintf(stderr,
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 "error: packet #%u is truncated in the capture\n",
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 pkt_idx);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 exit(1);
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 (udplen < 20) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 fprintf(stderr,
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 "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
131 pkt_idx);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 if (pkt[28] != 0x80) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 fprintf(stderr,
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 "error in packet #%u: unsupported RTP header structure\n",
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 pkt_idx);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 rtp_stream_logic(pkt + 28, pkt_idx);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 payload_len = udplen - 20;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 switch (payload_len) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 case 2:
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 if (pkt[40] == 0xBF)
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 break;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 goto bad_payload;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 case 31:
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 if ((pkt[40] & 0xF0) == 0xC0)
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 break;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 goto bad_payload;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 case 33:
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 if ((pkt[40] & 0xF0) == 0xD0)
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 break;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 /* FALL THRU */
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 default:
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 bad_payload:
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 fprintf(stderr, "error in packet #%u: unsupported payload\n",
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 pkt_idx);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 fwrite(pkt + 40, 1, payload_len, outfile);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 main(argc, argv)
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 char **argv;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 char errbuf[PCAP_ERRBUF_SIZE];
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 u_char *pkt;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 struct pcap_pkthdr pkthdr;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 unsigned pkt_idx;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 if (argc != 6) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 fprintf(stderr,
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 "usage: %s pcap-file src|dest ip-addr udp-port outfile\n",
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 argv[0]);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 pcap = pcap_open_offline(argv[1], errbuf);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 if (!pcap) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 fprintf(stderr, "%s: %s\n", argv[1], errbuf);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 check_dl_type();
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 if (!strcmp(argv[2], "src")) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 iphdr_addr_offset = 12;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 udphdr_port_offset = 0;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 } else if (!strcmp(argv[2], "dest")) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 iphdr_addr_offset = 16;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 udphdr_port_offset = 2;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 } else {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 fprintf(stderr,
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 "error: direction argument must be \"src\" or \"dest\"\n");
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 match_ip_addr = inet_addr(argv[3]);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 if (match_ip_addr == INADDR_NONE) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 fprintf(stderr, "error: IP address argument is invalid\n");
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 match_udp_port = htons(strtoul(argv[4], 0, 0));
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 outfile = fopen(argv[5], "w");
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 if (!outfile) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 perror(argv[5]);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 for (pkt_idx = 0; ; pkt_idx++) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 pkt = pcap_next(pcap, &pkthdr);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 if (!pkt)
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 break;
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 process_packet(pkt, (unsigned) pkthdr.caplen, pkt_idx);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 if (!stream_init_flag) {
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 fprintf(stderr, "error: specified RTP stream not found\n");
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 exit(1);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 }
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 fclose(outfile);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 exit(0);
851ca64e38e9 rtp-gsmfr-extr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 }