Skip to content

Commit 87b18d2

Browse files
ticpuorgads
authored andcommitted
Add support for raw IP pcap files
Files created from Wireshark by using "File -> Strip Headers" and that contain only the minimum amount of information to send RTP packets. No headers to strip in this case so set offset to 0. Documentation for DLT_RAW / raw IP / link layer 12 is available at: https://github.com/the-tcpdump-group/libpcap/blob/master/pcap/dlt.h
1 parent 5e17500 commit 87b18d2

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/prepare_pcap.c

+17-7
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ size_t get_ethertype_offset(int link, const uint8_t* pktdata)
148148
if (link == DLT_EN10MB) {
149149
/* srcmac[6], dstmac[6], ethertype[2] */
150150
offset = 12;
151+
/* Layer 3 IP packets / raw IP
152+
* https://github.com/the-tcpdump-group/libpcap/blob/master/pcap/dlt.h#L111
153+
*/
154+
} else if (link == DLT_RAW) {
155+
return 0;
151156
} else if (link == DLT_LINUX_SLL) {
152157
/* http://www.tcpdump.org/linktypes/LINKTYPE_LINUX_SLL.html */
153158
/* pkttype[2], arphrd_type[2], lladdrlen[2], lladdr[8], ethertype[2] */
@@ -223,14 +228,19 @@ int prepare_pkts(const char* file, pcap_pkts* pkts)
223228
ether_type_offset = get_ethertype_offset(datalink, pktdata);
224229
}
225230

226-
ethhdr = (ether_type_hdr *)(pktdata + ether_type_offset);
227-
if (ntohs(ethhdr->ether_type) != 0x0800 /* IPv4 */
228-
&& ntohs(ethhdr->ether_type) != 0x86dd) { /* IPv6 */
229-
fprintf(stderr, "Ignoring non IP{4,6} packet, got ether_type %hu!\n",
230-
ntohs(ethhdr->ether_type));
231-
continue;
231+
if (ether_type_offset > 0) {
232+
ethhdr = (ether_type_hdr *)(pktdata + ether_type_offset);
233+
if (ntohs(ethhdr->ether_type) != 0x0800 /* IPv4 */
234+
&& ntohs(ethhdr->ether_type) != 0x86dd) { /* IPv6 */
235+
fprintf(stderr, "Ignoring non IP{4,6} packet, got ether_type %hu (%04x)!\n",
236+
ntohs(ethhdr->ether_type), ethhdr->ether_type);
237+
continue;
238+
}
239+
iphdr = (struct ip*)((char*)ethhdr + sizeof(*ethhdr));
240+
} else {
241+
iphdr = (struct ip*)((char*)pktdata);
232242
}
233-
iphdr = (struct ip*)((char*)ethhdr + sizeof(*ethhdr));
243+
234244
if (iphdr && iphdr->ip_v == 6) {
235245
/* ipv6 */
236246
ip6hdr = (struct ip6_hdr*)(void*)iphdr;

0 commit comments

Comments
 (0)