Skip to content

Commit

Permalink
Fix loopback interface on OpenBSD (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
catap authored Sep 19, 2024
1 parent 158b0d3 commit 467b380
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/datalink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,33 @@ void dl_null(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
}
#pragma GCC diagnostic warning "-Wcast-align"

/* OpenBSD has it's own DLT_LOOP which similar to old DLT_NULL_BROKEN */
#ifdef DLT_LOOP

#define LOOP_HDRLEN 4

void dl_loop(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
{
u_int caplen = h->caplen;
u_int length = h->len;

if (length != caplen) {
DEBUG(6) ("warning: only captured %d bytes of %d byte null frame",
caplen, length);
}

if (caplen < LOOP_HDRLEN) {
DEBUG(6) ("warning: received incomplete null frame");
return;
}

struct timeval tv;
be13::packet_info pi(DLT_LOOP,h,p,tvshift(tv,h->ts),p+LOOP_HDRLEN,caplen - LOOP_HDRLEN);
be13::plugin::process_packet(pi);
}

#endif

static uint64_t counter=0;

#ifdef DLT_PPP_ETHER
Expand Down Expand Up @@ -293,6 +320,10 @@ void dl_linux_sll(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
/* List of callbacks for each data link type */
dlt_handler_t handlers[] = {
{ dl_null, DLT_NULL },
/* OpenBSD uses 12 at DLT_LOOP, so, it should be before constans */
#ifdef DLT_LOOP
{ dl_loop, DLT_LOOP },
#endif
/* Some systems define DLT_RAW as 12, some as 14, and some as 101.
* So it is hard-coded here.
*/
Expand Down

0 comments on commit 467b380

Please sign in to comment.