#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/fad-getad.c,v 1.1 2002-07-27 18:46:21 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/fad-getad.c,v 1.2 2002-07-30 08:12:13 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "os-proto.h"
#endif
+/*
+ * This is fun.
+ *
+ * In older BSD systems, socket addresses were fixed-length, and
+ * "sizeof (struct sockaddr)" gave the size of the structure.
+ * All addresses fit within a "struct sockaddr".
+ *
+ * In newer BSD systems, the socket address is variable-length, and
+ * there's an "sa_len" field giving the length of the structure;
+ * this allows socket addresses to be longer than 2 bytes of family
+ * and 14 bytes of data.
+ *
+ * Some commercial UNIXes use the old BSD scheme, some use the RFC 2553
+ * variant of the old BSD scheme (with "struct sockaddr_storage" rather
+ * than "struct sockaddr"), and some use the new BSD scheme.
+ *
+ * GNU libc uses neither scheme, but has an "SA_LEN()" macro that
+ * determines the size based on the address family.
+ */
+#ifndef SA_LEN
+#ifdef HAVE_SOCKADDR_SA_LEN
+#define SA_LEN(addr) ((addr)->sa_len)
+#else /* HAVE_SOCKADDR_SA_LEN */
+#ifdef HAVE_SOCKADDR_STORAGE
+#define SA_LEN(addr) (sizeof (struct sockaddr_storage))
+#else /* HAVE_SOCKADDR_STORAGE */
+#define SA_LEN(addr) (sizeof (struct sockaddr))
+#endif /* HAVE_SOCKADDR_STORAGE */
+#endif /* HAVE_SOCKADDR_SA_LEN */
+#endif /* SA_LEN */
+
/*
* Get a list of all interfaces that are up and that we can open.
* Returns -1 on error, 0 otherwise.
pcap_if_t *devlist = NULL;
struct ifaddrs *ifap, *ifa;
struct sockaddr *broadaddr, *dstaddr;
+ size_t broadaddr_size, dstaddr_size;
int ret = 0;
/*
* non-null on a non-point-to-point
* interface.
*/
- if (ifa->ifa_flags & IFF_BROADCAST)
+ if (ifa->ifa_flags & IFF_BROADCAST) {
broadaddr = ifa->ifa_broadaddr;
- else
+ broadaddr_size = SA_LEN(broadaddr);
+ } else {
broadaddr = NULL;
- if (ifa->ifa_flags & IFF_POINTOPOINT)
+ broadaddr_size = 0;
+ }
+ if (ifa->ifa_flags & IFF_POINTOPOINT) {
dstaddr = ifa->ifa_dstaddr;
- else
+ dstaddr_size = SA_LEN(ifa->ifa_dstaddr);
+ } else {
dstaddr = NULL;
+ dstaddr_size = 0;
+ }
/*
* Add information for this address to the list.
*/
if (add_addr_to_iflist(&devlist, ifa->ifa_name,
- ifa->ifa_flags, ifa->ifa_addr, ifa->ifa_netmask,
- broadaddr, dstaddr, errbuf) < 0) {
+ ifa->ifa_flags, ifa->ifa_addr, SA_LEN(ifa->ifa_addr),
+ ifa->ifa_netmask, SA_LEN(ifa->ifa_netmask),
+ broadaddr, broadaddr_size, dstaddr, dstaddr_size,
+ errbuf) < 0) {
ret = -1;
break;
}
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/fad-gifc.c,v 1.1 2002-07-27 18:46:21 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/fad-gifc.c,v 1.2 2002-07-30 08:12:13 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "os-proto.h"
#endif
+/*
+ * This is fun.
+ *
+ * In older BSD systems, socket addresses were fixed-length, and
+ * "sizeof (struct sockaddr)" gave the size of the structure.
+ * All addresses fit within a "struct sockaddr".
+ *
+ * In newer BSD systems, the socket address is variable-length, and
+ * there's an "sa_len" field giving the length of the structure;
+ * this allows socket addresses to be longer than 2 bytes of family
+ * and 14 bytes of data.
+ *
+ * Some commercial UNIXes use the old BSD scheme, some use the RFC 2553
+ * variant of the old BSD scheme (with "struct sockaddr_storage" rather
+ * than "struct sockaddr"), and some use the new BSD scheme.
+ *
+ * GNU libc uses neither scheme, but has an "SA_LEN()" macro that
+ * determines the size based on the address family.
+ *
+ * We assume that a UNIX that doesn't have "getifaddrs()" and doesn't have
+ * SIOCGLIFCONF, but has SIOCGIFCONF, uses "struct sockaddr" for the
+ * address in an entry returned by SIOCGIFCONF.
+ */
+#ifndef SA_LEN
+#ifdef HAVE_SOCKADDR_SA_LEN
+#define SA_LEN(addr) ((addr)->sa_len)
+#else /* HAVE_SOCKADDR_SA_LEN */
+#define SA_LEN(addr) (sizeof (struct sockaddr))
+#endif /* HAVE_SOCKADDR_SA_LEN */
+#endif /* SA_LEN */
+
#ifdef HAVE_PROC_NET_DEV
/*
* Get from "/proc/net/dev" all interfaces listed there; if they're
}
#endif /* HAVE_PROC_NET_DEV */
-/*
- * This is fun.
- *
- * In older BSD systems, socket addresses were fixed-length, and
- * "sizeof (struct sockaddr)" gave the size of the structure.
- * All addresses fit within a "struct sockaddr".
- *
- * In newer BSD systems, the socket address is variable-length, and
- * there's an "sa_len" field giving the length of the structure;
- * this allows socket addresses to be longer than 2 bytes of family
- * and 14 bytes of data.
- *
- * Some commercial UNIXes use the old BSD scheme, some use the RFC 2553
- * variant of the old BSD scheme (with "struct sockaddr_storage" rather
- * than "struct sockaddr"), and some use the new BSD scheme.
- *
- * GNU libc uses neither scheme, but has an "SA_LEN()" macro that
- * determines the size based on the address family.
- */
-#ifndef SA_LEN
-#ifdef HAVE_SOCKADDR_SA_LEN
-#define SA_LEN(addr) ((addr)->sa_len)
-#else /* HAVE_SOCKADDR_SA_LEN */
-#ifdef HAVE_SOCKADDR_STORAGE
-#define SA_LEN(addr) (sizeof (struct sockaddr_storage))
-#else /* HAVE_SOCKADDR_STORAGE */
-#define SA_LEN(addr) (sizeof (struct sockaddr))
-#endif /* HAVE_SOCKADDR_STORAGE */
-#endif /* HAVE_SOCKADDR_SA_LEN */
-#endif /* SA_LEN */
-
/*
* Get a list of all interfaces that are up and that we can open.
* Returns -1 on error, 0 otherwise.
unsigned buf_size;
struct ifreq ifrflags, ifrnetmask, ifrbroadaddr, ifrdstaddr;
struct sockaddr *netmask, *broadaddr, *dstaddr;
+ size_t netmask_size, broadaddr_size, dstaddr_size;
int ret = 0;
/*
* Not available.
*/
netmask = NULL;
+ netmask_size = 0;
} else {
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
"SIOCGIFNETMASK: %.*s: %s",
ret = -1;
break;
}
- } else
+ } else {
netmask = &ifrnetmask.ifr_addr;
+ netmask_size = SA_LEN(netmask);
+ }
/*
* Get the broadcast address for this address on this
* Not available.
*/
broadaddr = NULL;
+ broadaddr_size = 0;
} else {
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
"SIOCGIFBRDADDR: %.*s: %s",
ret = -1;
break;
}
- } else
+ } else {
broadaddr = &ifrbroadaddr.ifr_broadaddr;
+ broadaddr_size = SA_LEN(broadaddr);
+ }
} else {
/*
* Not a broadcast interface, so no broadcast
* address.
*/
broadaddr = NULL;
+ broadaddr_size = 0;
}
/*
* Not available.
*/
dstaddr = NULL;
+ dstaddr_size = 0;
} else {
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
"SIOCGIFDSTADDR: %.*s: %s",
ret = -1;
break;
}
- } else
+ } else {
dstaddr = &ifrdstaddr.ifr_dstaddr;
- } else
+ dstaddr_size = SA_LEN(dstaddr);
+ }
+ } else {
+ /*
+ * Not a point-to-point interface, so no destination
+ * address.
+ */
dstaddr = NULL;
+ dstaddr_size = 0;
+ }
/*
* Add information for this address to the list.
*/
if (add_addr_to_iflist(&devlist, ifrp->ifr_name,
ifrflags.ifr_flags, &ifrp->ifr_addr,
- netmask, broadaddr, dstaddr, errbuf) < 0) {
+ SA_LEN(&ifrp->ifr_addr), netmask, netmask_size,
+ broadaddr, broadaddr_size, dstaddr, dstaddr_size,
+ errbuf) < 0) {
ret = -1;
break;
}
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/fad-glifc.c,v 1.1 2002-07-27 18:46:21 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/fad-glifc.c,v 1.2 2002-07-30 08:12:13 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
*/
if (add_addr_to_iflist(&devlist, ifrp->lifr_name,
ifrflags.lifr_flags, (struct sockaddr *)&ifrp->lifr_addr,
- netmask, broadaddr, dstaddr, errbuf) < 0) {
+ sizeof (struct sockaddr_storage),
+ netmask, sizeof (struct sockaddr_storage),
+ broadaddr, sizeof (struct sockaddr_storage),
+ dstaddr, sizeof (struct sockaddr_storage), errbuf) < 0) {
ret = -1;
break;
}
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/inet.c,v 1.49 2002-07-27 18:45:35 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/inet.c,v 1.50 2002-07-30 08:12:14 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
(isdigit((unsigned char)((name)[2])) || (name)[2] == '\0'))
#endif
-/*
- * This is fun.
- *
- * In older BSD systems, socket addresses were fixed-length, and
- * "sizeof (struct sockaddr)" gave the size of the structure.
- * All addresses fit within a "struct sockaddr".
- *
- * In newer BSD systems, the socket address is variable-length, and
- * there's an "sa_len" field giving the length of the structure;
- * this allows socket addresses to be longer than 2 bytes of family
- * and 14 bytes of data.
- *
- * Some commercial UNIXes use the old BSD scheme, some use the RFC 2553
- * variant of the old BSD scheme (with "struct sockaddr_storage" rather
- * than "struct sockaddr"), and some use the new BSD scheme.
- *
- * GNU libc uses neither scheme, but has an "SA_LEN()" macro that
- * determines the size based on the address family.
- */
-#ifndef SA_LEN
-#ifdef HAVE_SOCKADDR_SA_LEN
-#define SA_LEN(addr) ((addr)->sa_len)
-#else /* HAVE_SOCKADDR_SA_LEN */
-#ifdef HAVE_SOCKADDR_STORAGE
-#define SA_LEN(addr) (sizeof (struct sockaddr_storage))
-#else /* HAVE_SOCKADDR_STORAGE */
-#define SA_LEN(addr) (sizeof (struct sockaddr))
-#endif /* HAVE_SOCKADDR_STORAGE */
-#endif /* HAVE_SOCKADDR_SA_LEN */
-#endif /* SA_LEN */
-
static struct sockaddr *
-dup_sockaddr(struct sockaddr *sa)
+dup_sockaddr(struct sockaddr *sa, size_t sa_len)
{
struct sockaddr *newsa;
- unsigned int size;
- size = SA_LEN(sa);
- if ((newsa = malloc(size)) == NULL)
+ if ((newsa = malloc(sa_len)) == NULL)
return (NULL);
- return (memcpy(newsa, sa, size));
+ return (memcpy(newsa, sa, sa_len));
}
static int
int
add_addr_to_iflist(pcap_if_t **alldevs, char *name, u_int flags,
- struct sockaddr *addr, struct sockaddr *netmask,
- struct sockaddr *broadaddr, struct sockaddr *dstaddr, char *errbuf)
+ struct sockaddr *addr, size_t addr_size,
+ struct sockaddr *netmask, size_t netmask_size,
+ struct sockaddr *broadaddr, size_t broadaddr_size,
+ struct sockaddr *dstaddr, size_t dstaddr_size,
+ char *errbuf)
{
pcap_if_t *curdev;
pcap_addr_t *curaddr, *prevaddr, *nextaddr;
curaddr->next = NULL;
if (addr != NULL) {
- curaddr->addr = dup_sockaddr(addr);
+ curaddr->addr = dup_sockaddr(addr, addr_size);
if (curaddr->addr == NULL) {
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
"malloc: %s", pcap_strerror(errno));
curaddr->addr = NULL;
if (netmask != NULL) {
- curaddr->netmask = dup_sockaddr(netmask);
+ curaddr->netmask = dup_sockaddr(netmask, netmask_size);
if (curaddr->netmask == NULL) {
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
"malloc: %s", pcap_strerror(errno));
curaddr->netmask = NULL;
if (broadaddr != NULL) {
- curaddr->broadaddr = dup_sockaddr(broadaddr);
+ curaddr->broadaddr = dup_sockaddr(broadaddr, broadaddr_size);
if (curaddr->broadaddr == NULL) {
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
"malloc: %s", pcap_strerror(errno));
curaddr->broadaddr = NULL;
if (dstaddr != NULL) {
- curaddr->dstaddr = dup_sockaddr(dstaddr);
+ curaddr->dstaddr = dup_sockaddr(dstaddr, dstaddr_size);
if (curaddr->dstaddr == NULL) {
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
"malloc: %s", pcap_strerror(errno));
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.36 2002-07-27 18:45:35 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.37 2002-07-30 08:12:14 guy Exp $ (LBL)
*/
#ifndef pcap_int_h
*/
int pcap_platform_finddevs(pcap_if_t **, char *);
int add_addr_to_iflist(pcap_if_t **, char *, u_int, struct sockaddr *,
- struct sockaddr *, struct sockaddr *, struct sockaddr *, char *);
+ size_t, struct sockaddr *, size_t, struct sockaddr *, size_t,
+ struct sockaddr *, size_t, char *);
int pcap_add_if(pcap_if_t **, char *, u_int, const char *, char *);