]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
BPF: Improve headers
authorRoy Marples <roy@marples.name>
Mon, 1 Jun 2026 20:20:01 +0000 (21:20 +0100)
committerRoy Marples <roy@marples.name>
Mon, 1 Jun 2026 20:23:38 +0000 (21:23 +0100)
src/bpf.c

index 78d9916674ac9d8e3c42c7decf7811b82ec949f5..1dd6b220c68af2ad6dd5cb86838a1cf0fe7a80ce 100644 (file)
--- a/src/bpf.c
+++ b/src/bpf.c
 #include <netinet/if_ether.h>
 
 #include <arpa/inet.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
 
-#ifdef __linux__
-/* Special BPF snowflake. */
+#include "config.h"
+#ifdef USE_LIBPCAP
+#include <pcap/bpf.h>
+#elif defined(__linux__)
 #include <linux/filter.h>
 #define bpf_insn sock_filter
 #else
 #include <net/bpf.h>
 #endif
 
-#include <errno.h>
-#include <fcntl.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-
 #include "arp.h"
 #include "bpf.h"
 #include "common.h"
@@ -268,7 +269,7 @@ static const struct bpf_insn bpf_arp_ether[] = {
        /* Make sure the hardware length matches. */
        BPF_STMT(BPF_LD + BPF_B + BPF_IND, offsetof(struct arphdr, ar_hln)),
        BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K,
-           sizeof(((struct ether_arp *)0)->arp_sha), 1, 0),
+           sizeof(((struct ether_header *)0)->ether_shost), 1, 0),
        BPF_STMT(BPF_RET + BPF_K, 0),
 };
 #define BPF_ARP_ETHER_LEN __arraycount(bpf_arp_ether)
@@ -314,8 +315,10 @@ bpf_arp_rw(const struct bpf *bpf, const struct in_addr *ia, bool recv)
        case ARPHRD_ETHER:
                memcpy(bp, bpf_arp_ether, sizeof(bpf_arp_ether));
                bp += BPF_ARP_ETHER_LEN;
-               arp_len = sizeof(struct ether_header) +
-                   sizeof(struct ether_arp);
+               arp_len = sizeof(struct ether_header) + sizeof(struct arphdr) +
+                   ((sizeof(((struct ether_header *)0)->ether_shost) +
+                        sizeof(uint32_t)) *
+                       2);
                break;
        default:
                errno = EINVAL;