Skip to content

Commit

Permalink
Add support for raw IP pcap files
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ticpu authored and orgads committed Oct 8, 2024
1 parent 5e17500 commit 87b18d2
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/prepare_pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ size_t get_ethertype_offset(int link, const uint8_t* pktdata)
if (link == DLT_EN10MB) {
/* srcmac[6], dstmac[6], ethertype[2] */
offset = 12;
/* Layer 3 IP packets / raw IP
* https://github.com/the-tcpdump-group/libpcap/blob/master/pcap/dlt.h#L111
*/
} else if (link == DLT_RAW) {
return 0;
} else if (link == DLT_LINUX_SLL) {
/* http://www.tcpdump.org/linktypes/LINKTYPE_LINUX_SLL.html */
/* pkttype[2], arphrd_type[2], lladdrlen[2], lladdr[8], ethertype[2] */
Expand Down Expand Up @@ -223,14 +228,19 @@ int prepare_pkts(const char* file, pcap_pkts* pkts)
ether_type_offset = get_ethertype_offset(datalink, pktdata);
}

ethhdr = (ether_type_hdr *)(pktdata + ether_type_offset);
if (ntohs(ethhdr->ether_type) != 0x0800 /* IPv4 */
&& ntohs(ethhdr->ether_type) != 0x86dd) { /* IPv6 */
fprintf(stderr, "Ignoring non IP{4,6} packet, got ether_type %hu!\n",
ntohs(ethhdr->ether_type));
continue;
if (ether_type_offset > 0) {
ethhdr = (ether_type_hdr *)(pktdata + ether_type_offset);
if (ntohs(ethhdr->ether_type) != 0x0800 /* IPv4 */
&& ntohs(ethhdr->ether_type) != 0x86dd) { /* IPv6 */
fprintf(stderr, "Ignoring non IP{4,6} packet, got ether_type %hu (%04x)!\n",
ntohs(ethhdr->ether_type), ethhdr->ether_type);
continue;
}
iphdr = (struct ip*)((char*)ethhdr + sizeof(*ethhdr));
} else {
iphdr = (struct ip*)((char*)pktdata);
}
iphdr = (struct ip*)((char*)ethhdr + sizeof(*ethhdr));

if (iphdr && iphdr->ip_v == 6) {
/* ipv6 */
ip6hdr = (struct ip6_hdr*)(void*)iphdr;
Expand Down

0 comments on commit 87b18d2

Please sign in to comment.