FreeCalypso > hg > rtp-debug-utils
comparison pcap-study/rtp-stream-dump.c @ 14:e7f43262efa1
rtp-stream-dump: add hex dump option
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 28 Jul 2024 01:53:41 +0000 |
parents | d59dbdfe1778 |
children |
comparison
equal
deleted
inserted
replaced
13:d59dbdfe1778 | 14:e7f43262efa1 |
---|---|
23 static unsigned iphdr_addr_offset, udphdr_port_offset; | 23 static unsigned iphdr_addr_offset, udphdr_port_offset; |
24 static unsigned link_hdr_len, ethertype_offset; | 24 static unsigned link_hdr_len, ethertype_offset; |
25 static int stream_init_flag, toad_init_flag; | 25 static int stream_init_flag, toad_init_flag; |
26 static unsigned last_seq, last_tstamp, stream_ssrc; | 26 static unsigned last_seq, last_tstamp, stream_ssrc; |
27 static struct timeval last_pkt_time; | 27 static struct timeval last_pkt_time; |
28 static int do_hexdump; | |
28 | 29 |
29 static void | 30 static void |
30 check_dl_type() | 31 check_dl_type() |
31 { | 32 { |
32 int dltype; | 33 int dltype; |
84 last_tstamp = cur_tstamp; | 85 last_tstamp = cur_tstamp; |
85 stream_ssrc = cur_ssrc; | 86 stream_ssrc = cur_ssrc; |
86 } | 87 } |
87 | 88 |
88 static void | 89 static void |
90 hexdump_payload(payload, payload_len) | |
91 u_char *payload; | |
92 unsigned payload_len; | |
93 { | |
94 unsigned off; | |
95 | |
96 for (off = 0; off < payload_len; off++) { | |
97 if ((off & 3) == 0) | |
98 putchar(' '); | |
99 printf(" %02X", payload[off]); | |
100 if ((off & 15) == 15 || off == payload_len - 1) | |
101 putchar('\n'); | |
102 } | |
103 } | |
104 | |
105 static void | |
89 process_packet(pkt, caplen, pkt_idx, pkt_time) | 106 process_packet(pkt, caplen, pkt_idx, pkt_time) |
90 u_char *pkt; | 107 u_char *pkt; |
91 unsigned caplen, pkt_idx; | 108 unsigned caplen, pkt_idx; |
92 struct timeval *pkt_time; | 109 struct timeval *pkt_time; |
93 { | 110 { |
134 "error in packet #%u: unsupported RTP header structure\n", | 151 "error in packet #%u: unsupported RTP header structure\n", |
135 pkt_idx); | 152 pkt_idx); |
136 exit(1); | 153 exit(1); |
137 } | 154 } |
138 rtp_stream_logic(pkt + 28, pkt_idx); | 155 rtp_stream_logic(pkt + 28, pkt_idx); |
156 payload_len = udplen - 20; | |
139 printf("pkt #%u seq 0x%04X ts 0x%08X: pt=%u M=%u len=%u", pkt_idx, | 157 printf("pkt #%u seq 0x%04X ts 0x%08X: pt=%u M=%u len=%u", pkt_idx, |
140 last_seq, last_tstamp, pkt[29] & 0x7F, pkt[29] >> 7, | 158 last_seq, last_tstamp, pkt[29] & 0x7F, pkt[29] >> 7, |
141 udplen - 20); | 159 payload_len); |
142 if (toad_init_flag && timercmp(pkt_time, &last_pkt_time, >=)) { | 160 if (toad_init_flag && timercmp(pkt_time, &last_pkt_time, >=)) { |
143 timersub(pkt_time, &last_pkt_time, &toad); | 161 timersub(pkt_time, &last_pkt_time, &toad); |
144 if (toad.tv_sec) | 162 if (toad.tv_sec) |
145 printf(", toad %u.%06u s", (unsigned) toad.tv_sec, | 163 printf(", toad %u.%06u s", (unsigned) toad.tv_sec, |
146 (unsigned) toad.tv_usec); | 164 (unsigned) toad.tv_usec); |
149 toad_us = toad.tv_usec % 1000; | 167 toad_us = toad.tv_usec % 1000; |
150 printf(", toad %u.%03u ms", toad_ms, toad_us); | 168 printf(", toad %u.%03u ms", toad_ms, toad_us); |
151 } | 169 } |
152 } | 170 } |
153 putchar('\n'); | 171 putchar('\n'); |
172 if (do_hexdump) | |
173 hexdump_payload(pkt + 40, payload_len); | |
154 bcopy(pkt_time, &last_pkt_time, sizeof(struct timeval)); | 174 bcopy(pkt_time, &last_pkt_time, sizeof(struct timeval)); |
155 toad_init_flag = 1; | 175 toad_init_flag = 1; |
156 } | 176 } |
157 | 177 |
158 main(argc, argv) | 178 main(argc, argv) |
161 char errbuf[PCAP_ERRBUF_SIZE]; | 181 char errbuf[PCAP_ERRBUF_SIZE]; |
162 u_char *pkt; | 182 u_char *pkt; |
163 struct pcap_pkthdr pkthdr; | 183 struct pcap_pkthdr pkthdr; |
164 unsigned pkt_idx; | 184 unsigned pkt_idx; |
165 | 185 |
166 if (argc != 5) { | 186 switch (argc) { |
167 fprintf(stderr, | 187 case 5: |
168 "usage: %s pcap-file src|dest ip-addr udp-port\n", | 188 do_hexdump = 0; |
189 break; | |
190 case 6: | |
191 if (strcmp(argv[5], "hex")) | |
192 goto usage; | |
193 do_hexdump = 1; | |
194 break; | |
195 default: | |
196 usage: | |
197 fprintf(stderr, | |
198 "usage: %s pcap-file src|dest ip-addr udp-port [hex]\n", | |
169 argv[0]); | 199 argv[0]); |
170 exit(1); | 200 exit(1); |
171 } | 201 } |
172 pcap = pcap_open_offline(argv[1], errbuf); | 202 pcap = pcap_open_offline(argv[1], errbuf); |
173 if (!pcap) { | 203 if (!pcap) { |