/*
- * Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2010-2012 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
#include <sys/types.h>
#include <sys/socket.h>
-#include <sys/param.h>
#include <stdio.h>
#ifdef STDC_HEADERS
# include <stdlib.h>
# define INADDR_NONE ((unsigned int)-1)
#endif
+static struct interface *interfaces;
+
/*
* Parse a space-delimited list of IP address/netmask pairs and
* store in a list of interface structures.
{
char *addrinfo, *addr, *mask;
struct interface *ifp;
+ debug_decl(set_interfaces, SUDO_DEBUG_NETIF)
addrinfo = estrdup(ai);
for (addr = strtok(addrinfo, " \t"); addr != NULL; addr = strtok(NULL, " \t")) {
*mask++ = '\0';
/* Parse addr and store in list. */
- ifp = emalloc(sizeof(*ifp));
+ ifp = ecalloc(1, sizeof(*ifp));
if (strchr(addr, ':')) {
/* IPv6 */
-#ifdef HAVE_IN6_ADDR
+#ifdef HAVE_STRUCT_IN6_ADDR
ifp->family = AF_INET6;
if (inet_pton(AF_INET6, addr, &ifp->addr.ip6) != 1 ||
inet_pton(AF_INET6, mask, &ifp->netmask.ip6) != 1)
interfaces = ifp;
}
efree(addrinfo);
+ debug_return;
+}
+
+struct interface *
+get_interfaces(void)
+{
+ return interfaces;
}
void
dump_interfaces(const char *ai)
{
char *cp, *addrinfo;
+ debug_decl(set_interfaces, SUDO_DEBUG_NETIF)
addrinfo = estrdup(ai);
sudo_printf(SUDO_CONV_INFO_MSG, "\t%s\n", cp);
efree(addrinfo);
+ debug_return;
}