summaryrefslogtreecommitdiffstats
path: root/net.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2013-02-19 13:37:42 +0000
committerRoy Marples <roy@marples.name>2013-02-19 13:37:42 +0000
commit4b0cbc89742e6eb28580231da2f1ca8597613794 (patch)
treef9bc04a269af8b7cdc6d717a9c63d1f7b82a6dcb /net.c
parentb3d0ed9f0df55b61e547bef3948015d8e4b6486d (diff)
downloaddhcpcd-4b0cbc89742e6eb28580231da2f1ca8597613794.tar.xz
Use a TAILQ macro for our interface list.
Diffstat (limited to 'net.c')
-rw-r--r--net.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/net.c b/net.c
index 028dd9fa..5245554a 100644
--- a/net.c
+++ b/net.c
@@ -199,13 +199,14 @@ up_interface(struct interface *iface)
return retval;
}
-struct interface *
+struct if_head *
discover_interfaces(int argc, char * const *argv)
{
struct ifaddrs *ifaddrs, *ifa;
char *p;
int i, sdl_type;
- struct interface *ifp, *ifs, *ifl;
+ struct if_head *ifs;
+ struct interface *ifp;
#ifdef __linux__
char ifn[IF_NAMESIZE];
#endif
@@ -227,7 +228,11 @@ discover_interfaces(int argc, char * const *argv)
if (getifaddrs(&ifaddrs) == -1)
return NULL;
- ifs = ifl = NULL;
+ ifs = malloc(sizeof(*ifs));
+ if (ifs == NULL)
+ return NULL;
+ TAILQ_INIT(ifs);
+
for (ifa = ifaddrs; ifa; ifa = ifa->ifa_next) {
if (ifa->ifa_addr != NULL) {
#ifdef AF_LINK
@@ -241,9 +246,10 @@ discover_interfaces(int argc, char * const *argv)
/* It's possible for an interface to have >1 AF_LINK.
* For our purposes, we use the first one. */
- for (ifp = ifs; ifp; ifp = ifp->next)
+ TAILQ_FOREACH(ifp, ifs, next) {
if (strcmp(ifp->name, ifa->ifa_name) == 0)
break;
+ }
if (ifp)
continue;
if (argc > 0) {
@@ -409,11 +415,7 @@ discover_interfaces(int argc, char * const *argv)
ifp->metric += 100;
}
- if (ifl)
- ifl->next = ifp;
- else
- ifs = ifp;
- ifl = ifp;
+ TAILQ_INSERT_TAIL(ifs, ifp, next);
}
freeifaddrs(ifaddrs);