aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Reed <darren.reed@oracle.com>2011-06-04 10:44:13 -0700
committerGuy Harris <guy@alum.mit.edu>2011-06-04 10:44:13 -0700
commit1332e38a469e8f1f31c4b2a38a41a7fd42330b3b (patch)
tree69e9304187e07d27634c6973a0c741da0730be41
parent0177044b9f53b8d9d4fa80c5846a62f9d5849e8b (diff)
Use BIOCSETLIF if available.
Solaris 11 will support the ioctl BIOCSETLIF. This operates on "struct lifname". Whilst there are other *LIF ioctls, only this one is important for libpcap. For most consumers, the primary difference is the length of the name allowed. The traditional ifname structure only allowed for 16 character interface names. The newer struct lifname allows for 32. With the presence of interface renaming, amongst other features, use of the struct lifname ioctls will be required for proper functionality. Reviewed-By: Guy Harris <guy@alum.mit.edu>
-rw-r--r--pcap-bpf.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/pcap-bpf.c b/pcap-bpf.c
index f0cb17c6..1d3c8cb4 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;
+ char *ifrname = ifr.lifr_name;
+ const size_t ifnamsiz = sizeof(ifr.lifr_name);
+#else
struct ifreq ifr;
+ 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) {