version 1.1.1.1, 2012/02/21 16:23:02
|
version 1.1.1.4, 2014/06/15 16:12:54
|
Line 1
|
Line 1
|
/* |
/* |
* Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com> | * Copyright (c) 2010-2013 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 |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
Line 18
|
Line 18
|
|
|
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <sys/socket.h> |
#include <sys/param.h> |
|
#include <stdio.h> |
#include <stdio.h> |
#ifdef STDC_HEADERS |
#ifdef STDC_HEADERS |
# include <stdlib.h> |
# include <stdlib.h> |
Line 52
|
Line 51
|
# define INADDR_NONE ((unsigned int)-1) |
# define INADDR_NONE ((unsigned int)-1) |
#endif |
#endif |
|
|
|
static struct interface_list interfaces; |
|
|
/* |
/* |
* Parse a space-delimited list of IP address/netmask pairs and |
* Parse a space-delimited list of IP address/netmask pairs and |
* store in a list of interface structures. |
* store in a list of interface structures. |
Line 61 set_interfaces(const char *ai)
|
Line 62 set_interfaces(const char *ai)
|
{ |
{ |
char *addrinfo, *addr, *mask; |
char *addrinfo, *addr, *mask; |
struct interface *ifp; |
struct interface *ifp; |
|
debug_decl(set_interfaces, SUDO_DEBUG_NETIF) |
|
|
addrinfo = estrdup(ai); |
addrinfo = estrdup(ai); |
for (addr = strtok(addrinfo, " \t"); addr != NULL; addr = strtok(NULL, " \t")) { |
for (addr = strtok(addrinfo, " \t"); addr != NULL; addr = strtok(NULL, " \t")) { |
Line 70 set_interfaces(const char *ai)
|
Line 72 set_interfaces(const char *ai)
|
*mask++ = '\0'; |
*mask++ = '\0'; |
|
|
/* Parse addr and store in list. */ |
/* Parse addr and store in list. */ |
ifp = emalloc(sizeof(*ifp)); | ifp = ecalloc(1, sizeof(*ifp)); |
if (strchr(addr, ':')) { |
if (strchr(addr, ':')) { |
/* IPv6 */ |
/* IPv6 */ |
#ifdef HAVE_IN6_ADDR | #ifdef HAVE_STRUCT_IN6_ADDR |
ifp->family = AF_INET6; |
ifp->family = AF_INET6; |
if (inet_pton(AF_INET6, addr, &ifp->addr.ip6) != 1 || |
if (inet_pton(AF_INET6, addr, &ifp->addr.ip6) != 1 || |
inet_pton(AF_INET6, mask, &ifp->netmask.ip6) != 1) |
inet_pton(AF_INET6, mask, &ifp->netmask.ip6) != 1) |
Line 85 set_interfaces(const char *ai)
|
Line 87 set_interfaces(const char *ai)
|
} else { |
} else { |
/* IPv4 */ |
/* IPv4 */ |
ifp->family = AF_INET; |
ifp->family = AF_INET; |
ifp->addr.ip4.s_addr = inet_addr(addr); | if (inet_pton(AF_INET, addr, &ifp->addr.ip4) != 1 || |
ifp->netmask.ip4.s_addr = inet_addr(mask); | inet_pton(AF_INET, mask, &ifp->netmask.ip4) != 1) { |
if (ifp->addr.ip4.s_addr == INADDR_NONE || | |
ifp->netmask.ip4.s_addr == INADDR_NONE) { | |
efree(ifp); |
efree(ifp); |
continue; |
continue; |
} |
} |
} |
} |
ifp->next = interfaces; | SLIST_INSERT_HEAD(&interfaces, ifp, entries); |
interfaces = ifp; | |
} |
} |
efree(addrinfo); |
efree(addrinfo); |
|
debug_return; |
} |
} |
|
|
|
struct interface_list * |
|
get_interfaces(void) |
|
{ |
|
return &interfaces; |
|
} |
|
|
void |
void |
dump_interfaces(const char *ai) |
dump_interfaces(const char *ai) |
{ |
{ |
char *cp, *addrinfo; |
char *cp, *addrinfo; |
|
debug_decl(set_interfaces, SUDO_DEBUG_NETIF) |
|
|
addrinfo = estrdup(ai); |
addrinfo = estrdup(ai); |
|
|
Line 111 dump_interfaces(const char *ai)
|
Line 118 dump_interfaces(const char *ai)
|
sudo_printf(SUDO_CONV_INFO_MSG, "\t%s\n", cp); |
sudo_printf(SUDO_CONV_INFO_MSG, "\t%s\n", cp); |
|
|
efree(addrinfo); |
efree(addrinfo); |
|
debug_return; |
} |
} |