Diff for /embedaddon/sudo/src/net_ifs.c between versions 1.1 and 1.1.1.3

version 1.1, 2012/02/21 16:23:02 version 1.1.1.3, 2013/07/22 10:46:13
Line 1 Line 1
 /*  /*
 * Copyright (c) 1996, 1998-2005, 2007-2010 * Copyright (c) 1996, 1998-2005, 2007-2013
  *      Todd C. Miller <Todd.Miller@courtesan.com>   *      Todd C. Miller <Todd.Miller@courtesan.com>
  *   *
  * Permission to use, copy, modify, and distribute this software for any   * Permission to use, copy, modify, and distribute this software for any
Line 32  struct rtentry; Line 32  struct rtentry;
   
 #include <sys/types.h>  #include <sys/types.h>
 #include <sys/socket.h>  #include <sys/socket.h>
 #include <sys/param.h>  
 #include <sys/time.h>  #include <sys/time.h>
 #include <sys/ioctl.h>  #include <sys/ioctl.h>
 #if defined(HAVE_SYS_SOCKIO_H) && !defined(SIOCGIFCONF)  #if defined(HAVE_SYS_SOCKIO_H) && !defined(SIOCGIFCONF)
Line 83  struct rtentry; Line 82  struct rtentry;
 #include "missing.h"  #include "missing.h"
 #include "alloc.h"  #include "alloc.h"
 #include "error.h"  #include "error.h"
   #include "sudo_debug.h"
   
 #define DEFAULT_TEXT_DOMAIN     "sudo"  #define DEFAULT_TEXT_DOMAIN     "sudo"
 #include "gettext.h"  #include "gettext.h"
Line 107  get_net_ifs(char **addrinfo) Line 107  get_net_ifs(char **addrinfo)
 {  {
     struct ifaddrs *ifa, *ifaddrs;      struct ifaddrs *ifa, *ifaddrs;
     struct sockaddr_in *sin;      struct sockaddr_in *sin;
#ifdef HAVE_IN6_ADDR#ifdef HAVE_STRUCT_IN6_ADDR
     struct sockaddr_in6 *sin6;      struct sockaddr_in6 *sin6;
     char addrbuf[INET6_ADDRSTRLEN];      char addrbuf[INET6_ADDRSTRLEN];
 #endif  #endif
     int ailen, i, len, num_interfaces = 0;      int ailen, i, len, num_interfaces = 0;
     char *cp;      char *cp;
       debug_decl(get_net_ifs, SUDO_DEBUG_NETIF)
   
     if (getifaddrs(&ifaddrs))      if (getifaddrs(&ifaddrs))
        return 0;        debug_return_int(0);
   
     /* Allocate space for the interfaces info string. */      /* Allocate space for the interfaces info string. */
     for (ifa = ifaddrs; ifa != NULL; ifa = ifa -> ifa_next) {      for (ifa = ifaddrs; ifa != NULL; ifa = ifa -> ifa_next) {
Line 126  get_net_ifs(char **addrinfo) Line 127  get_net_ifs(char **addrinfo)
   
         switch (ifa->ifa_addr->sa_family) {          switch (ifa->ifa_addr->sa_family) {
             case AF_INET:              case AF_INET:
#ifdef HAVE_IN6_ADDR#ifdef HAVE_STRUCT_IN6_ADDR
             case AF_INET6:              case AF_INET6:
 #endif  #endif
                 num_interfaces++;                  num_interfaces++;
Line 134  get_net_ifs(char **addrinfo) Line 135  get_net_ifs(char **addrinfo)
         }          }
     }      }
     if (num_interfaces == 0)      if (num_interfaces == 0)
        return 0;        debug_return_int(0);
     ailen = num_interfaces * 2 * INET6_ADDRSTRLEN;      ailen = num_interfaces * 2 * INET6_ADDRSTRLEN;
     *addrinfo = cp = emalloc(ailen);      *addrinfo = cp = emalloc(ailen);
   
Line 166  get_net_ifs(char **addrinfo) Line 167  get_net_ifs(char **addrinfo)
                 }                  }
                 cp += len;                  cp += len;
                 break;                  break;
#ifdef HAVE_IN6_ADDR#ifdef HAVE_STRUCT_IN6_ADDR
             case AF_INET6:              case AF_INET6:
                 sin6 = (struct sockaddr_in6 *)ifa->ifa_addr;                  sin6 = (struct sockaddr_in6 *)ifa->ifa_addr;
                 inet_ntop(AF_INET6, &sin6->sin6_addr, addrbuf, sizeof(addrbuf));                  inet_ntop(AF_INET6, &sin6->sin6_addr, addrbuf, sizeof(addrbuf));
Line 187  get_net_ifs(char **addrinfo) Line 188  get_net_ifs(char **addrinfo)
                 }                  }
                 cp += len;                  cp += len;
                 break;                  break;
#endif /* HAVE_IN6_ADDR */#endif /* HAVE_STRUCT_IN6_ADDR */
         }          }
     }      }
   
Line 197  done: Line 198  done:
 #else  #else
     efree(ifaddrs);      efree(ifaddrs);
 #endif  #endif
    return num_interfaces;    debug_return_int(num_interfaces);
 }  }
   
 #elif defined(SIOCGIFCONF) && !defined(STUB_LOAD_INTERFACES)  #elif defined(SIOCGIFCONF) && !defined(STUB_LOAD_INTERFACES)
Line 218  get_net_ifs(char **addrinfo) Line 219  get_net_ifs(char **addrinfo)
 #ifdef _ISC  #ifdef _ISC
     struct strioctl strioctl;      struct strioctl strioctl;
 #endif /* _ISC */  #endif /* _ISC */
       debug_decl(get_net_ifs, SUDO_DEBUG_NETIF)
   
     sock = socket(AF_INET, SOCK_DGRAM, 0);      sock = socket(AF_INET, SOCK_DGRAM, 0);
     if (sock < 0)      if (sock < 0)
        error(1, _("unable to open socket"));        fatal(_("unable to open socket"));
   
     /*      /*
      * Get interface configuration or return.       * Get interface configuration or return.
Line 250  get_net_ifs(char **addrinfo) Line 252  get_net_ifs(char **addrinfo)
   
     /* Allocate space for the maximum number of interfaces that could exist. */      /* Allocate space for the maximum number of interfaces that could exist. */
     if ((n = ifconf->ifc_len / sizeof(struct ifreq)) == 0)      if ((n = ifconf->ifc_len / sizeof(struct ifreq)) == 0)
        return 0;        debug_return_int(0);
     ailen = n * 2 * INET6_ADDRSTRLEN;      ailen = n * 2 * INET6_ADDRSTRLEN;
     *addrinfo = cp = emalloc(ailen);      *addrinfo = cp = emalloc(ailen);
   
Line 261  get_net_ifs(char **addrinfo) Line 263  get_net_ifs(char **addrinfo)
   
         /* Set i to the subscript of the next interface. */          /* Set i to the subscript of the next interface. */
         i += sizeof(struct ifreq);          i += sizeof(struct ifreq);
#ifdef HAVE_SA_LEN#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
         if (ifr->ifr_addr.sa_len > sizeof(ifr->ifr_addr))          if (ifr->ifr_addr.sa_len > sizeof(ifr->ifr_addr))
             i += ifr->ifr_addr.sa_len - sizeof(struct sockaddr);              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. */          /* Skip duplicates and interfaces with NULL addresses. */
         sin = (struct sockaddr_in *) &ifr->ifr_addr;          sin = (struct sockaddr_in *) &ifr->ifr_addr;
Line 327  done: Line 329  done:
     efree(ifconf_buf);      efree(ifconf_buf);
     (void) close(sock);      (void) close(sock);
   
    return num_interfaces;    debug_return_int(num_interfaces);
 }  }
   
 #else /* !SIOCGIFCONF || STUB_LOAD_INTERFACES */  #else /* !SIOCGIFCONF || STUB_LOAD_INTERFACES */
Line 338  done: Line 340  done:
 int  int
 get_net_ifs(char **addrinfo)  get_net_ifs(char **addrinfo)
 {  {
    return 0;    debug_decl(get_net_ifs, SUDO_DEBUG_NETIF)
     debug_return_int(0);
 }  }
   
 #endif /* SIOCGIFCONF && !STUB_LOAD_INTERFACES */  #endif /* SIOCGIFCONF && !STUB_LOAD_INTERFACES */

Removed from v.1.1  
changed lines
  Added in v.1.1.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>