Source: libpcap
Version: 1.10.6-1
Severity: important
Tags: patch

Hello,

Upstream updated some function names in the 1.10 branch, here is a patch
to update the hurd support (already fixed upstream). I have also
attached the resulting new patch, whichever is simpler for you to take.

Samuel

-- System Information:
Debian Release: forky/sid
  APT prefers testing
  APT policy: (990, 'testing'), (500, 'unstable-debug'), (500, 
'testing-debug'), (500, 'stable-security'), (500, 'stable-debug'), (500, 
'proposed-updates'), (500, 'oldstable-debug'), (500, 'oldoldstable'), (500, 
'buildd-unstable'), (500, 'unstable'), (500, 'stable'), (500, 'oldstable'), (1, 
'experimental-debug'), (1, 'buildd-experimental'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386, arm64

Kernel: Linux 7.0.10+deb14-amd64 (SMP w/22 CPU threads; PREEMPT)
Kernel taint flags: TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

-- 
Samuel
<N> bon comment on fait de l'investigation pour savoir qui est le vilain ?
<s> on débranche le routeur et on regarde qui s'affole
 -+- #ens-mim administre -+-
diff -ur libpcap-1.10.6/debian/patches/hurd.diff 
libpcap-1.10.6/debian/patches/hurd.diff
--- libpcap-1.10.6/debian/patches/hurd.diff     2026-02-15 19:18:22.000000000 
+0100
+++ libpcap-1.10.6/debian/patches/hurd.diff     2026-06-29 00:28:44.161910600 
+0200
@@ -4,14 +4,14 @@
 Forwarded: 
https://github.com/the-tcpdump-group/libpcap/commit/04b51af508caec959f695bc3bbb62afa97ca5b38
 
 ---
- configure.in |   6 ++
- pcap-hurd.c  | 255 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 2 files changed, 261 insertions(+)
+ configure.ac |   11 ++
+ pcap-hurd.c  |  263 
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 274 insertions(+)
  create mode 100644 pcap-hurd.c
 
 --- a/configure.ac
 +++ b/configure.ac
-@@ -749,6 +749,7 @@
+@@ -749,6 +749,7 @@ else
        AC_CHECK_HEADERS(net/nit.h sys/net/nit.h)
        AC_CHECK_HEADERS(linux/socket.h net/raw.h sys/dlpi.h)
        AC_CHECK_HEADERS(config/HaikuConfig.h)
@@ -19,7 +19,7 @@
  
        if test "$ac_cv_lbl_bpf_h_defines_biocsetif" = yes; then
                #
-@@ -810,6 +811,11 @@
+@@ -810,6 +811,11 @@ else
                # Haiku.
                #
                V_PCAP=haiku
@@ -31,7 +31,7 @@
        else
                #
                # We don't have any capture type we know about.
-@@ -1163,6 +1169,11 @@
+@@ -1153,6 +1159,11 @@ snoop)
        PLATFORM_C_SRC="pcap-snoop.c"
        ;;
  
@@ -191,7 +191,7 @@
 +              ph->mach_dev = MACH_PORT_NULL;
 +      }
 +
-+      pcap_cleanup_live_common(p);
++      pcapint_cleanup_live_common(p);
 +}
 +
 +static int
@@ -268,7 +268,7 @@
 +
 +      p->read_op = pcap_read_hurd;
 +      p->inject_op = pcap_inject_hurd;
-+      p->setfilter_op = install_bpf_program;
++      p->setfilter_op = pcapint_install_bpf_program;
 +      p->stats_op = pcap_stats_hurd;
 +
 +      return 0;
@@ -279,7 +279,7 @@
 +}
 +
 +pcap_t *
-+pcap_create_interface(const char *device _U_, char *ebuf)
++pcapint_create_interface(const char *device _U_, char *ebuf)
 +{
 +      struct pcap_hurd *ph;
 +      pcap_t *p;
@@ -296,7 +296,7 @@
 +}
 +
 +int
-+pcap_platform_finddevs(pcap_if_list_t *alldevsp, char *errbuf)
++pcapint_platform_finddevs(pcap_if_list_t *alldevsp, char *errbuf)
 +{
 +      return 0;
 +}
From: Richard Braun <[email protected]>
Date: Thu, 10 Apr 2014 01:26:01 +0200
Subject: [PATCH] Debian GNU/Hurd (with NETDDE) support
Forwarded: 
https://github.com/the-tcpdump-group/libpcap/commit/04b51af508caec959f695bc3bbb62afa97ca5b38

---
 configure.ac |   11 ++
 pcap-hurd.c  |  263 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 274 insertions(+)
 create mode 100644 pcap-hurd.c

--- a/configure.ac
+++ b/configure.ac
@@ -749,6 +749,7 @@ else
        AC_CHECK_HEADERS(net/nit.h sys/net/nit.h)
        AC_CHECK_HEADERS(linux/socket.h net/raw.h sys/dlpi.h)
        AC_CHECK_HEADERS(config/HaikuConfig.h)
+       AC_CHECK_HEADERS(hurd.h)
 
        if test "$ac_cv_lbl_bpf_h_defines_biocsetif" = yes; then
                #
@@ -810,6 +811,11 @@ else
                # Haiku.
                #
                V_PCAP=haiku
+       elif test "$ac_cv_header_hurd_h" = yes; then
+               #
+               # Hurd.
+               #
+               V_PCAP=hurd
        else
                #
                # We don't have any capture type we know about.
@@ -1153,6 +1159,11 @@ snoop)
        PLATFORM_C_SRC="pcap-snoop.c"
        ;;
 
+hurd)
+       PLATFORM_C_SRC="pcap-hurd.c"
+       LIBS="$LIBS -lrt"
+       ;;
+
 dag)
        #
        # --with-pcap=dag is the only way to get here, and it means
--- /dev/null
+++ b/pcap-hurd.c
@@ -0,0 +1,263 @@
+#define _GNU_SOURCE
+
+/* XXX Hack not to include the Mach BPF interface */
+#define _DEVICE_BPF_H_
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <fcntl.h>
+#include <hurd.h>
+#include <mach.h>
+#include <time.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <device/device.h>
+#include <device/device_types.h>
+#include <device/net_status.h>
+#include <net/if_ether.h>
+
+#include "pcap-int.h"
+
+struct pcap_hurd {
+       struct pcap_stat stat;
+       device_t mach_dev;
+       mach_port_t rcv_port;
+};
+
+static struct bpf_insn filter[] = {
+       { NETF_IN | NETF_OUT | NETF_BPF, 0, 0, 0 },
+       { BPF_RET | BPF_K, 0, 0, 1500 },
+};
+
+#define FILTER_COUNT (sizeof(filter) / sizeof(short))
+
+static int
+pcap_read_hurd(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
+{
+       struct net_rcv_msg *msg;
+       struct pcap_hurd *ph;
+       struct pcap_pkthdr h;
+       struct timespec ts;
+       int ret, wirelen, caplen;
+       u_char *pkt;
+       kern_return_t kr;
+
+       ph = p->priv;
+       msg = (struct net_rcv_msg *)p->buffer;
+
+retry:
+       if (p->break_loop) {
+               p->break_loop = 0;
+               return PCAP_ERROR_BREAK;
+       }
+
+       kr = mach_msg(&msg->msg_hdr, MACH_RCV_MSG | MACH_RCV_INTERRUPT, 0,
+                     p->bufsize, ph->rcv_port, MACH_MSG_TIMEOUT_NONE,
+                     MACH_PORT_NULL);
+
+       if (kr) {
+               if (kr == MACH_RCV_INTERRUPTED)
+                       goto retry;
+
+               snprintf(p->errbuf, sizeof(p->errbuf), "mach_msg: %s",
+                        pcap_strerror(kr));
+               return PCAP_ERROR;
+       }
+
+       ph->stat.ps_recv++;
+
+       /* XXX Ethernet support only */
+       wirelen = ETH_HLEN + msg->net_rcv_msg_packet_count
+                 - sizeof(struct packet_header);
+       pkt = p->buffer + offsetof(struct net_rcv_msg, packet)
+             + sizeof(struct packet_header) - ETH_HLEN;
+       memmove(pkt, p->buffer + offsetof(struct net_rcv_msg, header),
+               ETH_HLEN);
+
+       caplen = (wirelen > p->snapshot) ? p->snapshot : wirelen;
+       ret = bpf_filter(p->fcode.bf_insns, pkt, wirelen, caplen);
+
+       if (!ret)
+               goto out;
+
+       clock_gettime(CLOCK_REALTIME, &ts);
+       h.ts.tv_sec = ts.tv_sec;
+       h.ts.tv_usec = ts.tv_nsec / 1000;
+       h.len = wirelen;
+       h.caplen = caplen;
+       callback(user, &h, pkt);
+
+out:
+       return 1;
+}
+
+static int
+pcap_inject_hurd(pcap_t *p, const void *buf, int size)
+{
+       struct pcap_hurd *ph;
+       kern_return_t kr;
+       int count;
+
+       ph = p->priv;
+       kr = device_write(ph->mach_dev, D_NOWAIT, 0,
+                         (io_buf_ptr_t)buf, size, &count);
+
+       if (kr) {
+               snprintf(p->errbuf, sizeof(p->errbuf), "device_write: %s",
+                        pcap_strerror(kr));
+               return -1;
+       }
+
+       return count;
+}
+
+static int
+pcap_stats_hurd(pcap_t *p, struct pcap_stat *ps)
+{
+       struct pcap_hurd *ph;
+
+       ph = p->priv;
+       *ps = ph->stat;
+       return 0;
+}
+
+static void
+pcap_cleanup_hurd(pcap_t *p)
+{
+       struct pcap_hurd *ph;
+
+       ph = p->priv;
+
+       if (ph->rcv_port != MACH_PORT_NULL) {
+               mach_port_deallocate(mach_task_self(), ph->rcv_port);
+               ph->rcv_port = MACH_PORT_NULL;
+       }
+
+       if (ph->mach_dev != MACH_PORT_NULL) {
+               device_close(ph->mach_dev);
+               ph->mach_dev = MACH_PORT_NULL;
+       }
+
+       pcapint_cleanup_live_common(p);
+}
+
+static int
+pcap_activate_hurd(pcap_t *p)
+{
+       struct pcap_hurd *ph;
+       mach_port_t master;
+       kern_return_t kr;
+
+       ph = p->priv;
+
+       /* Try devnode first */
+       master = file_name_lookup(p->opt.device, O_READ | O_WRITE, 0);
+
+       if (master != MACH_PORT_NULL)
+               kr = device_open(master, D_WRITE | D_READ, "eth", 
&ph->mach_dev);
+       else {
+               /* If unsuccessful, try Mach device */
+               kr = get_privileged_ports(NULL, &master);
+
+               if (kr) {
+                       snprintf(p->errbuf, sizeof(p->errbuf),
+                                "get_privileged_ports: %s", pcap_strerror(kr));
+                       goto error;
+               }
+
+               kr = device_open(master, D_READ | D_WRITE, p->opt.device,
+                                &ph->mach_dev);
+       }
+
+       mach_port_deallocate(mach_task_self(), master);
+
+       if (kr) {
+               snprintf(p->errbuf, sizeof(p->errbuf), "device_open: %s",
+                        pcap_strerror(kr));
+               goto error;
+       }
+
+       kr = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE,
+                               &ph->rcv_port);
+
+       if (kr) {
+               snprintf(p->errbuf, sizeof(p->errbuf), "mach_port_allocate: %s",
+                        pcap_strerror(kr));
+               goto error;
+       }
+
+       kr = device_set_filter(ph->mach_dev, ph->rcv_port,
+                              MACH_MSG_TYPE_MAKE_SEND, 0,
+                              (filter_array_t)filter, FILTER_COUNT);
+
+       if (kr) {
+               snprintf(p->errbuf, sizeof(p->errbuf), "device_set_filter: %s",
+                        pcap_strerror(kr));
+               goto error;
+       }
+
+       /* XXX Ethernet only currently */
+       p->linktype = DLT_EN10MB;
+
+       p->bufsize = sizeof(struct net_rcv_msg);
+       p->buffer = malloc(p->bufsize);
+
+       if (p->buffer == NULL) {
+               snprintf(p->errbuf, sizeof(p->errbuf), "malloc: %s",
+                        pcap_strerror(errno));
+               goto error;
+       }
+
+       p->dlt_list = malloc(sizeof(*p->dlt_list));
+
+       if (p->dlt_list != NULL)
+               *p->dlt_list = DLT_EN10MB;
+
+       p->read_op = pcap_read_hurd;
+       p->inject_op = pcap_inject_hurd;
+       p->setfilter_op = pcapint_install_bpf_program;
+       p->stats_op = pcap_stats_hurd;
+
+       return 0;
+
+error:
+       pcap_cleanup_hurd(p);
+       return PCAP_ERROR;
+}
+
+pcap_t *
+pcapint_create_interface(const char *device _U_, char *ebuf)
+{
+       struct pcap_hurd *ph;
+       pcap_t *p;
+
+       p = PCAP_CREATE_COMMON(ebuf, struct pcap_hurd);
+       if (p == NULL)
+               return NULL;
+
+       ph = p->priv;
+       ph->mach_dev = MACH_PORT_NULL;
+       ph->rcv_port = MACH_PORT_NULL;
+       p->activate_op = pcap_activate_hurd;
+       return p;
+}
+
+int
+pcapint_platform_finddevs(pcap_if_list_t *alldevsp, char *errbuf)
+{
+       return 0;
+}
+
+/*
+ * Libpcap version string.
+ */
+const char *
+pcap_lib_version(void)
+{
+       return PCAP_VERSION_STRING;
+}

Reply via email to