version 1.3, 2002/01/23 23:03:24 |
version 1.4, 2003/03/15 21:23:54 |
|
|
/* |
/* |
* Copyright (c) 1996, 1998-2001 Todd C. Miller <Todd.Miller@courtesan.com> |
* Copyright (c) 1996, 1998-2003 Todd C. Miller <Todd.Miller@courtesan.com> |
* All rights reserved. |
* All rights reserved. |
* |
* |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
|
|
#include "interfaces.h" |
#include "interfaces.h" |
|
|
#ifndef lint |
#ifndef lint |
static const char rcsid[] = "$Sudo: interfaces.c,v 1.63 2002/01/18 19:17:07 millert Exp $"; |
static const char rcsid[] = "$Sudo: interfaces.c,v 1.68 2003/03/15 20:31:02 millert Exp $"; |
#endif /* lint */ |
#endif /* lint */ |
|
|
|
|
|
|
return; |
return; |
|
|
/* Allocate space for the interfaces list. */ |
/* Allocate space for the interfaces list. */ |
for (ifa = ifaddrs; ifa -> ifa_next; ifa = ifa -> ifa_next) { |
for (ifa = ifaddrs; ifa != NULL; ifa = ifa -> ifa_next) { |
/* Skip interfaces marked "down" and "loopback". */ |
/* Skip interfaces marked "down" and "loopback". */ |
if (ifa->ifa_addr == NULL || !(ifa->ifa_flags & IFF_UP) || |
if (ifa->ifa_addr == NULL || !(ifa->ifa_flags & IFF_UP) || |
(ifa->ifa_flags & IFF_LOOPBACK)) |
(ifa->ifa_flags & IFF_LOOPBACK)) |
|
|
break; |
break; |
} |
} |
} |
} |
|
if (num_interfaces == 0) |
|
return; |
interfaces = |
interfaces = |
(struct interface *) emalloc(sizeof(struct interface) * num_interfaces); |
(struct interface *) emalloc2(num_interfaces, sizeof(struct interface)); |
|
|
/* Store the ip addr / netmask pairs. */ |
/* Store the ip addr / netmask pairs. */ |
for (ifa = ifaddrs, i = 0; ifa -> ifa_next; ifa = ifa -> ifa_next) { |
for (ifa = ifaddrs, i = 0; ifa != NULL; ifa = ifa -> ifa_next) { |
/* Skip interfaces marked "down" and "loopback". */ |
/* Skip interfaces marked "down" and "loopback". */ |
if (ifa->ifa_addr == NULL || !(ifa->ifa_flags & IFF_UP) || |
if (ifa->ifa_addr == NULL || !(ifa->ifa_flags & IFF_UP) || |
(ifa->ifa_flags & IFF_LOOPBACK)) |
(ifa->ifa_flags & IFF_LOOPBACK)) |
|
|
} |
} |
|
|
/* |
/* |
* Get interface configuration or return (leaving num_interfaces 0) |
* Get interface configuration or return (leaving num_interfaces == 0) |
*/ |
*/ |
for (;;) { |
for (;;) { |
ifconf_buf = erealloc(ifconf_buf, len); |
ifconf_buf = erealloc(ifconf_buf, len); |
|
|
} |
} |
|
|
/* Allocate space for the maximum number of interfaces that could exist. */ |
/* Allocate space for the maximum number of interfaces that could exist. */ |
n = ifconf->ifc_len / sizeof(struct ifreq); |
if ((n = ifconf->ifc_len / sizeof(struct ifreq)) == 0) |
interfaces = (struct interface *) emalloc(sizeof(struct interface) * n); |
return; |
|
interfaces = (struct interface *) emalloc2(n, sizeof(struct interface)); |
|
|
/* For each interface, store the ip address and netmask. */ |
/* For each interface, store the ip address and netmask. */ |
for (i = 0; i < ifconf->ifc_len; ) { |
for (i = 0; i < ifconf->ifc_len; ) { |
|
|
/* If the expected size < real size, realloc the array. */ |
/* If the expected size < real size, realloc the array. */ |
if (n != num_interfaces) { |
if (n != num_interfaces) { |
if (num_interfaces != 0) |
if (num_interfaces != 0) |
interfaces = (struct interface *) erealloc(interfaces, |
interfaces = (struct interface *) erealloc3(interfaces, |
sizeof(struct interface) * num_interfaces); |
num_interfaces, sizeof(struct interface)); |
else |
else |
free(interfaces); |
free(interfaces); |
} |
} |