changelog entry, too
[debian/sudo] / src / net_ifs.c
index f6de0808f94a7b01a8753c9a21787b19feb72eb7..a5c0fee95cd58b30a5e9321e6e71a9c0cd0e7299 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -32,7 +32,6 @@ struct rtentry;
 
 #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)
@@ -83,6 +82,10 @@ struct rtentry;
 #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
@@ -104,15 +107,16 @@ get_net_ifs(char **addrinfo)
 {
     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) {
@@ -123,7 +127,7 @@ get_net_ifs(char **addrinfo)
 
        switch (ifa->ifa_addr->sa_family) {
            case AF_INET:
-#ifdef HAVE_IN6_ADDR
+#ifdef HAVE_STRUCT_IN6_ADDR
            case AF_INET6:
 #endif
                num_interfaces++;
@@ -131,7 +135,7 @@ get_net_ifs(char **addrinfo)
        }
     }
     if (num_interfaces == 0)
-       return 0;
+       debug_return_int(0);
     ailen = num_interfaces * 2 * INET6_ADDRSTRLEN;
     *addrinfo = cp = emalloc(ailen);
 
@@ -149,7 +153,7 @@ get_net_ifs(char **addrinfo)
                    "%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;
@@ -158,19 +162,19 @@ get_net_ifs(char **addrinfo)
                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;
@@ -179,12 +183,12 @@ get_net_ifs(char **addrinfo)
                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 */
        }
     }
 
@@ -194,7 +198,7 @@ done:
 #else
     efree(ifaddrs);
 #endif
-    return num_interfaces;
+    debug_return_int(num_interfaces);
 }
 
 #elif defined(SIOCGIFCONF) && !defined(STUB_LOAD_INTERFACES)
@@ -215,10 +219,11 @@ get_net_ifs(char **addrinfo)
 #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.
@@ -247,7 +252,7 @@ get_net_ifs(char **addrinfo)
 
     /* 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);
 
@@ -258,10 +263,10 @@ get_net_ifs(char **addrinfo)
 
        /* 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;
@@ -289,7 +294,7 @@ get_net_ifs(char **addrinfo)
            "%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;
@@ -313,7 +318,7 @@ get_net_ifs(char **addrinfo)
        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;
@@ -324,7 +329,7 @@ done:
     efree(ifconf_buf);
     (void) close(sock);
 
-    return num_interfaces;
+    debug_return_int(num_interfaces);
 }
 
 #else /* !SIOCGIFCONF || STUB_LOAD_INTERFACES */
@@ -335,7 +340,8 @@ done:
 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 */