Skip to content

Commit fa31d9e

Browse files
committed
merge libpcap-1.10.6
1 parent 4aa2ebd commit fa31d9e

40 files changed

+1911
-824
lines changed

external/bsd/libpcap/dist/dlpisubs.c

Lines changed: 126 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: dlpisubs.c,v 1.6 2024/09/02 15:33:36 christos Exp $ */
1+
/* $NetBSD: dlpisubs.c,v 1.7 2026/03/18 23:43:20 christos Exp $ */
22

33
/*
44
* This code is derived from code formerly in pcap-dlpi.c, originally
@@ -14,7 +14,7 @@
1414
*/
1515

1616
#include <sys/cdefs.h>
17-
__RCSID("$NetBSD: dlpisubs.c,v 1.6 2024/09/02 15:33:36 christos Exp $");
17+
__RCSID("$NetBSD: dlpisubs.c,v 1.7 2026/03/18 23:43:20 christos Exp $");
1818

1919
#include <config.h>
2020

@@ -65,10 +65,20 @@ __RCSID("$NetBSD: dlpisubs.c,v 1.6 2024/09/02 15:33:36 christos Exp $");
6565
#include <stropts.h>
6666
#include <unistd.h>
6767

68+
#include <sys/ioctl.h>
69+
#include <sys/socket.h>
70+
#include <sys/sockio.h>
71+
72+
#include <net/if.h>
73+
6874
#ifdef HAVE_LIBDLPI
6975
#include <libdlpi.h>
7076
#endif
7177

78+
#ifdef HAVE_ZONE_H
79+
#include <zone.h>
80+
#endif
81+
7282
#include "pcap-int.h"
7383
#include "dlpisubs.h"
7484

@@ -418,3 +428,117 @@ pcap_stream_err(const char *func, int err, char *errbuf)
418428
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, err, "%s", func);
419429
}
420430
#endif
431+
432+
int
433+
handle_nonexistent_dlpi_device(const char *ifname, char *errbuf)
434+
{
435+
int fd;
436+
int status;
437+
#ifdef LIFNAMSIZ
438+
struct lifreq lifr;
439+
#else
440+
struct ifreq ifr;
441+
#endif
442+
443+
#ifdef LIFNAMSIZ
444+
if (strlen(ifname) >= sizeof(lifr.lifr_name)) {
445+
#else
446+
if (strlen(ifname) >= sizeof(ifr.ifr_name)) {
447+
#endif
448+
/*
449+
* The name is too long, so it can't possibly exist.
450+
*/
451+
strlcpy(errbuf, "", PCAP_ERRBUF_SIZE);
452+
return (PCAP_ERROR_NO_SUCH_DEVICE);
453+
}
454+
455+
/*
456+
* Try to get a socket on which to do an ioctl to get the
457+
* interface's flags.
458+
*/
459+
fd = socket(AF_INET, SOCK_DGRAM, 0);
460+
if (fd < 0) {
461+
/* That failed; report that as the error. */
462+
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
463+
errno, "Can't open socket to get interface flags");
464+
return (PCAP_ERROR);
465+
}
466+
467+
#ifdef LIFNAMSIZ
468+
pcapint_strlcpy(lifr.lifr_name, ifname, sizeof(lifr.lifr_name));
469+
status = ioctl(fd, SIOCGLIFFLAGS, (char *)&lifr);
470+
#else
471+
pcapint_strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
472+
status = ioctl(fd, SIOCGIFFLAGS, (char *)&ifr);
473+
#endif
474+
475+
if (status < 0) {
476+
if (errno == ENXIO || errno == EINVAL) {
477+
/*
478+
* macOS, *BSD, and Solaris return one of
479+
* those two errors if the device doesn't exist.
480+
*/
481+
strlcpy(errbuf, "", PCAP_ERRBUF_SIZE);
482+
close(fd);
483+
return (PCAP_ERROR_NO_SUCH_DEVICE);
484+
}
485+
486+
/*
487+
* Some other error.
488+
*/
489+
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, errno,
490+
"Can't get interface flags");
491+
close(fd);
492+
return (PCAP_ERROR);
493+
}
494+
495+
/*
496+
* The interface exists.
497+
*/
498+
close(fd);
499+
500+
#ifdef HAVE_ZONE_H
501+
/*
502+
* If we're not in a global zone, the problem is probably
503+
* that the zone we're in doesn't happen to have any
504+
* DLPI devices. Exclusive-IP non-global zones have
505+
* their own interfaces and have DLPI devices for them:
506+
*
507+
* https://docs.oracle.com/cd/E37838_01/html/E61040/z.config.ov-6.html#VLZCRgekkb
508+
*
509+
* https://docs.oracle.com/cd/E19044-01/sol.containers/817-1592/geprv/index.html
510+
*
511+
* but shared-IP non-global zones don't:
512+
*
513+
* https://docs.oracle.com/cd/E37838_01/html/E61040/z.config.ov-6.html#VLZCRgekku
514+
*/
515+
if (getzoneid() != GLOBAL_ZONEID) {
516+
/*
517+
* Not a global zone; note that capturing on network
518+
* interfaces is only supported for interfaces
519+
* in an exclusive-IP zone.
520+
*/
521+
snprintf(errbuf, PCAP_ERRBUF_SIZE,
522+
"Capturing on interfaces in a non-global zone is supported only for interfaces in exclusive-IP zones");
523+
return (PCAP_ERROR_CAPTURE_NOTSUP);
524+
}
525+
#endif /* HAVE_ZONE_H */
526+
527+
/*
528+
* Some other problem; just report it as not having
529+
* a DLPI device. We don't report the DLPI device
530+
* name, so people don't get confused and think, for
531+
* example, that if they can't capture on that interface
532+
* on Solaris prior to Solaris 11 the fix is to change
533+
* libpcap (or the application that uses it) to look
534+
* for something other than "/dev/{ifname}", as the fix
535+
* is to use Solaris 11 or some operating system other
536+
* than Solaris - you just *can't* capture on that
537+
* interface on Solaris prior to Solaris 11, the lack
538+
* of a DLPI device for the loopback interface is just
539+
* a symptom of that inability.
540+
*/
541+
snprintf(errbuf, PCAP_ERRBUF_SIZE,
542+
"Capturing on that interface is not supported - no DLPI device found");
543+
return (PCAP_ERROR_CAPTURE_NOTSUP);
544+
}

external/bsd/libpcap/dist/dlpisubs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: dlpisubs.h,v 1.2 2014/11/19 19:33:30 christos Exp $ */
1+
/* $NetBSD: dlpisubs.h,v 1.3 2026/03/18 23:43:20 christos Exp $ */
22

33
#ifndef dlpisubs_h
44
#define dlpisubs_h
@@ -32,6 +32,7 @@ int pcap_conf_bufmod(pcap_t *, int);
3232
#endif
3333
int pcap_alloc_databuf(pcap_t *);
3434
int strioctl(int, int, int, char *);
35+
int handle_nonexistent_dlpi_device(const char *ifname, char *errbuf);
3536

3637
#ifdef __cplusplus
3738
}

external/bsd/libpcap/dist/fad-getad.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: fad-getad.c,v 1.6 2024/09/02 15:33:36 christos Exp $ */
1+
/* $NetBSD: fad-getad.c,v 1.7 2026/03/18 23:43:20 christos Exp $ */
22

33
/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
44
/*
@@ -35,7 +35,7 @@
3535
*/
3636

3737
#include <sys/cdefs.h>
38-
__RCSID("$NetBSD: fad-getad.c,v 1.6 2024/09/02 15:33:36 christos Exp $");
38+
__RCSID("$NetBSD: fad-getad.c,v 1.7 2026/03/18 23:43:20 christos Exp $");
3939

4040
#include <config.h>
4141

@@ -167,7 +167,7 @@ pcapint_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
167167
{
168168
struct ifaddrs *ifap, *ifa;
169169
struct sockaddr *addr, *netmask, *broadaddr, *dstaddr;
170-
size_t addr_size, broadaddr_size, dstaddr_size;
170+
size_t addr_size, netmask_size, broadaddr_size, dstaddr_size;
171171
int ret = 0;
172172
char *p, *q;
173173

@@ -240,11 +240,18 @@ pcapint_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
240240
if (ifa->ifa_addr != NULL) {
241241
addr = ifa->ifa_addr;
242242
addr_size = SA_LEN(addr);
243-
netmask = ifa->ifa_netmask;
243+
if (ifa->ifa_netmask != NULL) {
244+
netmask = ifa->ifa_netmask;
245+
netmask_size = SA_LEN(ifa->ifa_netmask);
246+
} else {
247+
netmask = NULL;
248+
netmask_size = 0;
249+
}
244250
} else {
245251
addr = NULL;
246252
addr_size = 0;
247253
netmask = NULL;
254+
netmask_size = 0;
248255
}
249256

250257
/*
@@ -284,7 +291,7 @@ pcapint_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
284291
*/
285292
if (pcapint_add_addr_to_if(devlistp, ifa->ifa_name, ifa->ifa_flags,
286293
get_flags_func,
287-
addr, addr_size, netmask, addr_size,
294+
addr, addr_size, netmask, netmask_size,
288295
broadaddr, broadaddr_size, dstaddr, dstaddr_size,
289296
errbuf) < 0) {
290297
ret = -1;

0 commit comments

Comments
 (0)