aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXin Li <delphij@FreeBSD.org>2010-03-10 15:55:44 -0800
committerGuy Harris <guy@alum.mit.edu>2010-03-10 15:55:44 -0800
commitf6cbf3b4de55ebbe6bfea1013a0fb462ee1aa75b (patch)
tree161765af45d11f5c3dce1f0ba921e73522d5c457
parentc3184553dfb1592db54bef442770666e03272d91 (diff)
Update to handle arbitrary-length interface descriptions on FreeBSD.
Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r--CREDITS1
-rw-r--r--inet.c40
2 files changed, 29 insertions, 12 deletions
diff --git a/CREDITS b/CREDITS
index 1c20f03..128c055 100644
--- a/CREDITS
+++ b/CREDITS
@@ -129,6 +129,7 @@ Additional people who have contributed patches:
Uwe Girlich <Uwe dot Girlich at philosys dot de>
Wesley Shields <wxs at FreeBSD dot org>
Xianjie Zhang <xzhang at cup dot hp dot com>
+ Xin Li <delphij at FreeBSD dot org>
Yen Yen Lim
Yvan Vanhullebus <vanhu at sourceforge dot net>
Yoann Vandoorselaere <yoann at prelude-ids dot org>
diff --git a/inet.c b/inet.c
index 494de09..0b16a65 100644
--- a/inet.c
+++ b/inet.c
@@ -417,10 +417,9 @@ add_addr_to_iflist(pcap_if_t **alldevs, const char *name, u_int flags,
int s;
struct ifreq ifrdesc;
#ifndef IFDESCRSIZE
-#define _IFDESCRSIZE 64
- char ifdescr[_IFDESCRSIZE];
-#else /* IFDESCRSIZE */
- char ifdescr[IFDESCRSIZE];
+ size_t descrlen = 64;
+#else
+ size_t descrlen = IFDESCRSIZE;
#endif /* IFDESCRSIZE */
#endif /* SIOCGIFDESCR */
@@ -430,28 +429,45 @@ add_addr_to_iflist(pcap_if_t **alldevs, const char *name, u_int flags,
*/
memset(&ifrdesc, 0, sizeof ifrdesc);
strlcpy(ifrdesc.ifr_name, name, sizeof ifrdesc.ifr_name);
+ s = socket(AF_INET, SOCK_DGRAM, 0);
+ if (s >= 0) {
+ for (;;) {
+ free(description);
+ if ((description = malloc(descrlen)) != NULL) {
#ifdef __FreeBSD__
- ifrdesc.ifr_buffer.buffer = ifdescr;
- ifrdesc.ifr_buffer.length = sizeof(ifdescr);
+ ifrdesc.ifr_buffer.buffer = description;
+ ifrdesc.ifr_buffer.length = descrlen;
#else /* __FreeBSD__ */
- ifrdesc.ifr_data = (caddr_t)ifdescr;
+ ifrdesc.ifr_data = (caddr_t)description;
#endif /* __FreeBSD__ */
- s = socket(AF_INET, SOCK_DGRAM, 0);
- if (s >= 0) {
- if (ioctl(s, SIOCGIFDESCR, &ifrdesc) == 0 &&
- strlen(ifdescr) != 0)
- description = ifdescr;
+ if (ioctl(s, SIOCGIFDESCR, &ifrdesc) == 0)
+ break;
+#ifdef __FreeBSD__
+ else if (errno == ENAMETOOLONG)
+ descrlen = ifrdesc.ifr_buffer.length;
+#endif /* __FreeBSD__ */
+ else
+ break;
+ } else
+ break;
+ }
close(s);
+ if (description != NULL && strlen(description) == 0) {
+ free(description);
+ description = NULL;
+ }
}
#endif /* SIOCGIFDESCR */
if (add_or_find_if(&curdev, alldevs, name, flags, description,
errbuf) == -1) {
+ free(description);
/*
* Error - give up.
*/
return (-1);
}
+ free(description);
if (curdev == NULL) {
/*
* Device wasn't added because it can't be opened.