FreeCalypso > hg > rtp-debug-utils
comparison pcap-study/rtp-stream-dump.c @ 13:d59dbdfe1778
rtp-stream-dump: compute and print time-of-arrival delta (toad)
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sat, 27 Jul 2024 23:39:50 +0000 |
| parents | e686bc92c7d8 |
| children | e7f43262efa1 |
comparison
equal
deleted
inserted
replaced
| 12:b5e73d5ebcd1 | 13:d59dbdfe1778 |
|---|---|
| 20 static pcap_t *pcap; | 20 static pcap_t *pcap; |
| 21 static in_addr_t match_ip_addr; | 21 static in_addr_t match_ip_addr; |
| 22 static u_short match_udp_port; | 22 static u_short match_udp_port; |
| 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; | 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 | 28 |
| 28 static void | 29 static void |
| 29 check_dl_type() | 30 check_dl_type() |
| 30 { | 31 { |
| 31 int dltype; | 32 int dltype; |
| 83 last_tstamp = cur_tstamp; | 84 last_tstamp = cur_tstamp; |
| 84 stream_ssrc = cur_ssrc; | 85 stream_ssrc = cur_ssrc; |
| 85 } | 86 } |
| 86 | 87 |
| 87 static void | 88 static void |
| 88 process_packet(pkt, caplen, pkt_idx) | 89 process_packet(pkt, caplen, pkt_idx, pkt_time) |
| 89 u_char *pkt; | 90 u_char *pkt; |
| 90 unsigned caplen, pkt_idx; | 91 unsigned caplen, pkt_idx; |
| 92 struct timeval *pkt_time; | |
| 91 { | 93 { |
| 92 unsigned udplen, payload_len; | 94 unsigned udplen, payload_len; |
| 95 struct timeval toad; | |
| 96 unsigned toad_ms, toad_us; | |
| 93 | 97 |
| 94 if (caplen < link_hdr_len + 28) | 98 if (caplen < link_hdr_len + 28) |
| 95 return; | 99 return; |
| 96 if (link_hdr_len) { | 100 if (link_hdr_len) { |
| 97 if (pkt[ethertype_offset] != 0x08) | 101 if (pkt[ethertype_offset] != 0x08) |
| 130 "error in packet #%u: unsupported RTP header structure\n", | 134 "error in packet #%u: unsupported RTP header structure\n", |
| 131 pkt_idx); | 135 pkt_idx); |
| 132 exit(1); | 136 exit(1); |
| 133 } | 137 } |
| 134 rtp_stream_logic(pkt + 28, pkt_idx); | 138 rtp_stream_logic(pkt + 28, pkt_idx); |
| 135 printf("pkt #%u seq 0x%04X ts 0x%08X: pt=%u M=%u len=%u\n", pkt_idx, | 139 printf("pkt #%u seq 0x%04X ts 0x%08X: pt=%u M=%u len=%u", pkt_idx, |
| 136 last_seq, last_tstamp, pkt[29] & 0x7F, pkt[29] >> 7, | 140 last_seq, last_tstamp, pkt[29] & 0x7F, pkt[29] >> 7, |
| 137 udplen - 20); | 141 udplen - 20); |
| 142 if (toad_init_flag && timercmp(pkt_time, &last_pkt_time, >=)) { | |
| 143 timersub(pkt_time, &last_pkt_time, &toad); | |
| 144 if (toad.tv_sec) | |
| 145 printf(", toad %u.%06u s", (unsigned) toad.tv_sec, | |
| 146 (unsigned) toad.tv_usec); | |
| 147 else { | |
| 148 toad_ms = toad.tv_usec / 1000; | |
| 149 toad_us = toad.tv_usec % 1000; | |
| 150 printf(", toad %u.%03u ms", toad_ms, toad_us); | |
| 151 } | |
| 152 } | |
| 153 putchar('\n'); | |
| 154 bcopy(pkt_time, &last_pkt_time, sizeof(struct timeval)); | |
| 155 toad_init_flag = 1; | |
| 138 } | 156 } |
| 139 | 157 |
| 140 main(argc, argv) | 158 main(argc, argv) |
| 141 char **argv; | 159 char **argv; |
| 142 { | 160 { |
| 176 match_udp_port = htons(strtoul(argv[4], 0, 0)); | 194 match_udp_port = htons(strtoul(argv[4], 0, 0)); |
| 177 for (pkt_idx = 0; ; pkt_idx++) { | 195 for (pkt_idx = 0; ; pkt_idx++) { |
| 178 pkt = pcap_next(pcap, &pkthdr); | 196 pkt = pcap_next(pcap, &pkthdr); |
| 179 if (!pkt) | 197 if (!pkt) |
| 180 break; | 198 break; |
| 181 process_packet(pkt, (unsigned) pkthdr.caplen, pkt_idx); | 199 process_packet(pkt, (unsigned) pkthdr.caplen, pkt_idx, |
| 200 &pkthdr.ts); | |
| 182 } | 201 } |
| 183 if (!stream_init_flag) { | 202 if (!stream_init_flag) { |
| 184 fprintf(stderr, "error: specified RTP stream not found\n"); | 203 fprintf(stderr, "error: specified RTP stream not found\n"); |
| 185 exit(1); | 204 exit(1); |
| 186 } | 205 } |
