From owner-svn-src-all@FreeBSD.ORG Fri Mar 11 00:38:07 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9B4BE1065672; Fri, 11 Mar 2011 00:38:07 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6ECA68FC0C; Fri, 11 Mar 2011 00:38:07 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p2B0c7nc060851; Fri, 11 Mar 2011 00:38:07 GMT (envelope-from delphij@svn.freebsd.org) Received: (from delphij@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p2B0c7CL060849; Fri, 11 Mar 2011 00:38:07 GMT (envelope-from delphij@svn.freebsd.org) Message-Id: <201103110038.p2B0c7CL060849@svn.freebsd.org> From: Xin LI Date: Fri, 11 Mar 2011 00:38:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r219472 - head/contrib/libpcap X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Mar 2011 00:38:07 -0000 Author: delphij Date: Fri Mar 11 00:38:07 2011 New Revision: 219472 URL: http://svn.freebsd.org/changeset/base/219472 Log: 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 Modified: head/contrib/libpcap/inet.c Modified: head/contrib/libpcap/inet.c ============================================================================== --- head/contrib/libpcap/inet.c Thu Mar 10 23:53:01 2011 (r219471) +++ head/contrib/libpcap/inet.c Fri Mar 11 00:38:07 2011 (r219472) @@ -431,26 +431,54 @@ add_addr_to_iflist(pcap_if_t **alldevs, 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);