/*
- * Copyright (c) 1996, 1998-2005, 2007-2010
+ * Copyright (c) 1996, 1998-2005, 2007-2013
* Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
#include <sys/types.h>
#include <sys/socket.h>
-#include <sys/param.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#if defined(HAVE_SYS_SOCKIO_H) && !defined(SIOCGIFCONF)
#include "missing.h"
#include "alloc.h"
#include "error.h"
+#include "sudo_debug.h"
+
+#define DEFAULT_TEXT_DOMAIN "sudo"
+#include "gettext.h"
/* Minix apparently lacks IFF_LOOPBACK */
#ifndef IFF_LOOPBACK
{
struct ifaddrs *ifa, *ifaddrs;
struct sockaddr_in *sin;
-#ifdef HAVE_IN6_ADDR
+#ifdef HAVE_STRUCT_IN6_ADDR
struct sockaddr_in6 *sin6;
char addrbuf[INET6_ADDRSTRLEN];
#endif
int ailen, i, len, num_interfaces = 0;
char *cp;
+ debug_decl(get_net_ifs, SUDO_DEBUG_NETIF)
if (getifaddrs(&ifaddrs))
- return 0;
+ debug_return_int(0);
/* Allocate space for the interfaces info string. */
for (ifa = ifaddrs; ifa != NULL; ifa = ifa -> ifa_next) {
switch (ifa->ifa_addr->sa_family) {
case AF_INET:
-#ifdef HAVE_IN6_ADDR
+#ifdef HAVE_STRUCT_IN6_ADDR
case AF_INET6:
#endif
num_interfaces++;
}
}
if (num_interfaces == 0)
- return 0;
+ debug_return_int(0);
ailen = num_interfaces * 2 * INET6_ADDRSTRLEN;
*addrinfo = cp = emalloc(ailen);
"%s%s/", cp == *addrinfo ? "" : " ",
inet_ntoa(sin->sin_addr));
if (len <= 0 || len >= ailen - (*addrinfo - cp)) {
- warningx("load_interfaces: overflow detected");
+ warningx(_("load_interfaces: overflow detected"));
goto done;
}
cp += len;
len = snprintf(cp, ailen - (*addrinfo - cp),
"%s", inet_ntoa(sin->sin_addr));
if (len <= 0 || len >= ailen - (*addrinfo - cp)) {
- warningx("load_interfaces: overflow detected");
+ warningx(_("load_interfaces: overflow detected"));
goto done;
}
cp += len;
break;
-#ifdef HAVE_IN6_ADDR
+#ifdef HAVE_STRUCT_IN6_ADDR
case AF_INET6:
sin6 = (struct sockaddr_in6 *)ifa->ifa_addr;
inet_ntop(AF_INET6, &sin6->sin6_addr, addrbuf, sizeof(addrbuf));
len = snprintf(cp, ailen - (*addrinfo - cp),
"%s%s/", cp == *addrinfo ? "" : " ", addrbuf);
if (len <= 0 || len >= ailen - (*addrinfo - cp)) {
- warningx("load_interfaces: overflow detected");
+ warningx(_("load_interfaces: overflow detected"));
goto done;
}
cp += len;
inet_ntop(AF_INET6, &sin6->sin6_addr, addrbuf, sizeof(addrbuf));
len = snprintf(cp, ailen - (*addrinfo - cp), "%s", addrbuf);
if (len <= 0 || len >= ailen - (*addrinfo - cp)) {
- warningx("load_interfaces: overflow detected");
+ warningx(_("load_interfaces: overflow detected"));
goto done;
}
cp += len;
break;
-#endif /* HAVE_IN6_ADDR */
+#endif /* HAVE_STRUCT_IN6_ADDR */
}
}
#else
efree(ifaddrs);
#endif
- return num_interfaces;
+ debug_return_int(num_interfaces);
}
#elif defined(SIOCGIFCONF) && !defined(STUB_LOAD_INTERFACES)
#ifdef _ISC
struct strioctl strioctl;
#endif /* _ISC */
+ debug_decl(get_net_ifs, SUDO_DEBUG_NETIF)
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0)
- error(1, "cannot open socket");
+ fatal(_("unable to open socket"));
/*
* Get interface configuration or return.
/* Allocate space for the maximum number of interfaces that could exist. */
if ((n = ifconf->ifc_len / sizeof(struct ifreq)) == 0)
- return 0;
+ debug_return_int(0);
ailen = n * 2 * INET6_ADDRSTRLEN;
*addrinfo = cp = emalloc(ailen);
/* Set i to the subscript of the next interface. */
i += sizeof(struct ifreq);
-#ifdef HAVE_SA_LEN
+#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
if (ifr->ifr_addr.sa_len > sizeof(ifr->ifr_addr))
i += ifr->ifr_addr.sa_len - sizeof(struct sockaddr);
-#endif /* HAVE_SA_LEN */
+#endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
/* Skip duplicates and interfaces with NULL addresses. */
sin = (struct sockaddr_in *) &ifr->ifr_addr;
"%s%s/", cp == *addrinfo ? "" : " ",
inet_ntoa(sin->sin_addr));
if (len <= 0 || len >= ailen - (*addrinfo - cp)) {
- warningx("load_interfaces: overflow detected");
+ warningx(_("load_interfaces: overflow detected"));
goto done;
}
cp += len;
len = snprintf(cp, ailen - (*addrinfo - cp),
"%s", inet_ntoa(sin->sin_addr));
if (len <= 0 || len >= ailen - (*addrinfo - cp)) {
- warningx("load_interfaces: overflow detected");
+ warningx(_("load_interfaces: overflow detected"));
goto done;
}
cp += len;
efree(ifconf_buf);
(void) close(sock);
- return num_interfaces;
+ debug_return_int(num_interfaces);
}
#else /* !SIOCGIFCONF || STUB_LOAD_INTERFACES */
int
get_net_ifs(char **addrinfo)
{
- return 0;
+ debug_decl(get_net_ifs, SUDO_DEBUG_NETIF)
+ debug_return_int(0);
}
#endif /* SIOCGIFCONF && !STUB_LOAD_INTERFACES */