Skip to content

Commit

Permalink
Update to handle arbitrary-length interface descriptions on FreeBSD.
Browse files Browse the repository at this point in the history
Reviewed-by: Guy Harris <guy@alum.mit.edu>
  • Loading branch information
delphij authored and guyharris committed Mar 10, 2010
1 parent c318455 commit f6cbf3b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
1 change: 1 addition & 0 deletions CREDITS
Expand Up @@ -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>
Expand Down
40 changes: 28 additions & 12 deletions inet.c
Expand Up @@ -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 */

Expand All @@ -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.
Expand Down

0 comments on commit f6cbf3b

Please sign in to comment.