version 1.13, 2009/08/07 19:35:55 |
version 1.14, 2009/09/11 22:06:29 |
Line 63 static void in_status(prop_dictionary_t, |
|
Line 63 static void in_status(prop_dictionary_t, |
|
static void in_commit_address(prop_dictionary_t, prop_dictionary_t); |
static void in_commit_address(prop_dictionary_t, prop_dictionary_t); |
static void in_alias(const char *, prop_dictionary_t, prop_dictionary_t, |
static void in_alias(const char *, prop_dictionary_t, prop_dictionary_t, |
struct in_aliasreq *); |
struct in_aliasreq *); |
static void in_preference(const char *, const struct sockaddr *); |
|
|
|
static struct afswtch af = { |
static struct afswtch af = { |
.af_name = "inet", .af_af = AF_INET, .af_status = in_status, |
.af_name = "inet", .af_af = AF_INET, .af_status = in_status, |
Line 139 in_alias(const char *ifname, prop_dictio |
|
Line 138 in_alias(const char *ifname, prop_dictio |
|
} |
} |
} |
} |
|
|
static int16_t |
|
in_get_preference(const char *ifname, const struct sockaddr *sa) |
|
{ |
|
struct if_addrprefreq ifap; |
|
int s; |
|
|
|
if ((s = getsock(AF_INET)) == -1) { |
|
if (errno == EPROTONOSUPPORT) |
|
return 0; |
|
err(EXIT_FAILURE, "socket"); |
|
} |
|
memset(&ifap, 0, sizeof(ifap)); |
|
estrlcpy(ifap.ifap_name, ifname, sizeof(ifap.ifap_name)); |
|
memcpy(&ifap.ifap_addr, sa, MIN(sizeof(ifap.ifap_addr), sa->sa_len)); |
|
if (ioctl(s, SIOCGIFADDRPREF, &ifap) == -1) { |
|
if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) |
|
return 0; |
|
warn("SIOCGIFADDRPREF"); |
|
} |
|
return ifap.ifap_preference; |
|
} |
|
|
|
static void |
|
in_preference(const char *ifname, const struct sockaddr *sa) |
|
{ |
|
int16_t preference; |
|
|
|
if (lflag) |
|
return; |
|
|
|
preference = in_get_preference(ifname, sa); |
|
printf(" preference %" PRId16, preference); |
|
} |
|
|
|
static void |
static void |
in_status(prop_dictionary_t env, prop_dictionary_t oenv, bool force) |
in_status(prop_dictionary_t env, prop_dictionary_t oenv, bool force) |
{ |
{ |
struct ifaddrs *ifap, *ifa; |
struct ifaddrs *ifap, *ifa; |
struct in_aliasreq ifra; |
struct in_aliasreq ifra; |
int printprefs = 0; |
bool printprefs = false; |
const char *ifname; |
const char *ifname; |
|
|
if ((ifname = getifname(env)) == NULL) |
if ((ifname = getifname(env)) == NULL) |
Line 187 in_status(prop_dictionary_t env, prop_di |
|
Line 152 in_status(prop_dictionary_t env, prop_di |
|
if (getifaddrs(&ifap) != 0) |
if (getifaddrs(&ifap) != 0) |
err(EXIT_FAILURE, "getifaddrs"); |
err(EXIT_FAILURE, "getifaddrs"); |
|
|
/* Print address preference numbers if any address has a non-zero |
printprefs = ifa_any_preferences(ifname, ifap, AF_INET); |
* preference assigned. |
|
*/ |
|
for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { |
|
if (strcmp(ifname, ifa->ifa_name) != 0) |
|
continue; |
|
if (ifa->ifa_addr->sa_family != AF_INET) |
|
continue; |
|
if (in_get_preference(ifa->ifa_name, ifa->ifa_addr) != 0) { |
|
printprefs = 1; |
|
break; |
|
} |
|
} |
|
for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { |
for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { |
if (strcmp(ifname, ifa->ifa_name) != 0) |
if (strcmp(ifname, ifa->ifa_name) != 0) |
continue; |
continue; |
Line 213 in_status(prop_dictionary_t env, prop_di |
|
Line 167 in_status(prop_dictionary_t env, prop_di |
|
memcpy(&ifra.ifra_addr, ifa->ifa_addr, ifa->ifa_addr->sa_len); |
memcpy(&ifra.ifra_addr, ifa->ifa_addr, ifa->ifa_addr->sa_len); |
in_alias(ifa->ifa_name, env, oenv, &ifra); |
in_alias(ifa->ifa_name, env, oenv, &ifra); |
if (printprefs) |
if (printprefs) |
in_preference(ifa->ifa_name, ifa->ifa_addr); |
ifa_print_preference(ifa->ifa_name, ifa->ifa_addr); |
printf("\n"); |
printf("\n"); |
} |
} |
freeifaddrs(ifap); |
freeifaddrs(ifap); |