summaryrefslogtreecommitdiffstats
path: root/contrib/libpcap
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2011-03-11 00:38:07 +0000
committerdelphij <delphij@FreeBSD.org>2011-03-11 00:38:07 +0000
commit8c8d7206ece7a4dc88c61d5910c6724b0137b26a (patch)
tree44649e7212b50f7f7410b04965b046881f454a4e /contrib/libpcap
parentc922219ced7087f1e7269b8cc8289a02c24fa3e0 (diff)
downloadFreeBSD-src-8c8d7206ece7a4dc88c61d5910c6724b0137b26a.zip
FreeBSD-src-8c8d7206ece7a4dc88c61d5910c6724b0137b26a.tar.gz
Merge my change against libpcap trunk revision
c65292b04b98d6a76d58c5a54ca8f81463bf24de to support new SIOCGIFDESCR ioctl interface which was too late for libpcap 1.1.1. Reported by: brucec Noticed by: wxs
Diffstat (limited to 'contrib/libpcap')
-rw-r--r--contrib/libpcap/inet.c50
1 files changed, 39 insertions, 11 deletions
diff --git a/contrib/libpcap/inet.c b/contrib/libpcap/inet.c
index 0b16a65..178eb81 100644
--- a/contrib/libpcap/inet.c
+++ b/contrib/libpcap/inet.c
@@ -431,26 +431,54 @@ add_addr_to_iflist(pcap_if_t **alldevs, const char *name, u_int flags,
strlcpy(ifrdesc.ifr_name, name, sizeof ifrdesc.ifr_name);
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s >= 0) {
+#ifdef __FreeBSD__
+ /*
+ * On FreeBSD, if the buffer isn't big enough for the
+ * description, the ioctl succeeds, but the description
+ * isn't copied, ifr_buffer.length is set to the description
+ * length, and ifr_buffer.buffer is set to NULL.
+ */
for (;;) {
free(description);
if ((description = malloc(descrlen)) != NULL) {
-#ifdef __FreeBSD__
ifrdesc.ifr_buffer.buffer = description;
ifrdesc.ifr_buffer.length = descrlen;
-#else /* __FreeBSD__ */
- ifrdesc.ifr_data = (caddr_t)description;
-#endif /* __FreeBSD__ */
- if (ioctl(s, SIOCGIFDESCR, &ifrdesc) == 0)
- break;
-#ifdef __FreeBSD__
- else if (errno == ENAMETOOLONG)
- descrlen = ifrdesc.ifr_buffer.length;
-#endif /* __FreeBSD__ */
- else
+ if (ioctl(s, SIOCGIFDESCR, &ifrdesc) == 0) {
+ if (ifrdesc.ifr_buffer.buffer ==
+ description)
+ break;
+ else
+ descrlen = ifrdesc.ifr_buffer.length;
+ } else {
+ /*
+ * Failed to get interface description.
+ */
+ free(description);
+ description = NULL;
break;
+ }
} else
break;
}
+#else /* __FreeBSD__ */
+ /*
+ * The only other OS that currently supports
+ * SIOCGIFDESCR is OpenBSD, and it has no way
+ * to get the description length - it's clamped
+ * to a maximum of IFDESCRSIZE.
+ */
+ if ((description = malloc(descrlen)) != NULL) {
+ ifrdesc.ifr_data = (caddr_t)description;
+ if (ioctl(s, SIOCGIFDESCR, &ifrdesc) != 0) {
+ /*
+ * Failed to get interface description.
+ */
+ free(description);
+ description = NULL;
+ }
+ } else
+ break;
+#endif /* __FreeBSD__ */
close(s);
if (description != NULL && strlen(description) == 0) {
free(description);
OpenPOWER on IntegriCloud