tcpdump mailing list archives

Use of BIOCSETLIF prefered on Solaris


From: Darren Reed <darren.reed () oracle com>
Date: Wed, 12 Jan 2011 15:59:54 +1100

When BPF was ported to Solaris, all of the ioctl operations
that use "struct ifreq" had a clone made that uses "struct lifreq".
So far as I know, "struct lifreq" is a Solaris-ism. One of the
main differences between "struct ifreq" and "struct lifreq" is
that the interface name can be 32 bytes long in "struct lifreq"
but only 16 bytes long in "struct ifreq". Generally, Solaris
supports an interface name length of 32 bytes, so the preference
would be to see libpcap do likewise.

The change required is to issue BIOCSETLIF instead of
BIOCSETIF. The latter does and will continue to work but
with interface names limited to 16 bytes.

Something similar to the patch below is what is required.

Darren

diff --git a/pcap-bpf.c b/pcap-bpf.c
index bcbfbef..b4c519c 100644
--- a/pcap-bpf.c
+++ b/pcap-bpf.c
@@ -1459,7 +1459,15 @@ pcap_activate_bpf(pcap_t *p)
{
       int status = 0;
       int fd;
+#ifdef LIFNAMSIZ
+       struct lifreq ifr;
+       const char *ifrname = ifr.lifr_name;
+       const size_t ifnamsiz = sizeof(ifr.lifr_name);
+#else
       struct ifreq ifr;
+       const char *ifrname = ifr.ifr_name;
+       const size_t ifnamsiz = sizeof(ifr.ifr_name);
+#endif
       struct bpf_version bv;
#ifdef __APPLE__
       int sockfd;
@@ -1551,9 +1559,8 @@ pcap_activate_bpf(pcap_t *p)
                                        */
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
                                       if (sockfd != -1) {
-                                               strlcpy(ifr.ifr_name,
-                                                   p->opt.source,
-                                                   sizeof(ifr.ifr_name));
+                                               strlcpy(ifrname,
+ p->opt.source, ifnamsiz); if (ioctl(sockfd, SIOCGIFFLAGS,
                                                   (char *)&ifr) < 0) {
                                                       /*
@@ -1667,7 +1674,7 @@ pcap_activate_bpf(pcap_t *p)
                           pcap_strerror(errno));
                       goto bad;
               }
- (void)strncpy(ifr.ifr_name, p->opt.source, sizeof(ifr.ifr_name))
+               (void)strncpy(ifrname, p->opt.source, ifnamsiz);
               if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) < 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCSETIF: %s: %s
                           p->opt.source, pcap_strerror(errno));
@@ -1697,9 +1704,13 @@ pcap_activate_bpf(pcap_t *p)
                       /*
                        * Now bind to the device.
                        */
-                       (void)strncpy(ifr.ifr_name, p->opt.source,
-                           sizeof(ifr.ifr_name));
-                       if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) < 0) {
+                       (void)strncpy(ifrname, p->opt.source, ifnamsiz);
+#ifdef BIOCSETLIF
+                       if (ioctl(fd, BIOCSETLIF, (caddr_t)&ifr) < 0)
+#else
+                       if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) < 0)
+#endif
+                       {
                               status = check_setif_failure(p, errno);
                               goto bad;
                       }
@@ -1726,9 +1737,12 @@ pcap_activate_bpf(pcap_t *p)
                                */
                               (void) ioctl(fd, BIOCSBLEN, (caddr_t)&v);

-                               (void)strncpy(ifr.ifr_name, p->opt.source,
-                                   sizeof(ifr.ifr_name));
+ (void)strncpy(ifrname, p->opt.source, ifnamsiz);
+#ifdef BIOCSETLIF
+ if (ioctl(fd, BIOCSETLIF, (caddr_t)&ifr) >= 0)
+#else
if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) >= 0)
+#endif
break; /* that size worked; we're done

                               if (errno != ENOBUFS) {

-
This is the tcpdump-workers list.
Visit https://cod.sandelman.ca/ to unsubscribe.


Current thread: