struct in_addr S_find_linklocal_address(ServiceRef service_p) { int count; int i; interface_t * if_p; struct in_addr ll_addr; ll_addr = linklocal_get_address(service_p); if (ll_addr.s_addr != 0) { return (ll_addr); } if_p = service_interface(service_p); count = if_inet_count(if_p); for (i = 0; i < count; i++) { inet_addrinfo_t * info = if_inet_addr_at(if_p, i); if (ip_is_linklocal(info->addr)) { my_log(LOG_DEBUG, "LINKLOCAL %s: found address " IP_FORMAT, if_name(if_p), IP_LIST(&info->addr)); return (info->addr); } } return (G_ip_zeroes); }
int if_inet_find_ip(interface_t * if_p, struct in_addr iaddr) { int i; for (i = 0; i < if_inet_count(if_p); i++) { inet_addrinfo_t * info = if_inet_addr_at(if_p, i); if (info->addr.s_addr == iaddr.s_addr) { return (i); } } return (INDEX_BAD); }
void ifl_print(interface_list_t * list_p) { int i; int count = 0; printf("Interface count = %d\n", list_p->count); for (i = 0; i < list_p->count; i++) { interface_t * if_p = list_p->list + i; int j; if (i > 0) printf("\n"); printf("%s: type %d\n", if_name(if_p), if_ift_type(if_p)); for (j = 0; j < if_inet_count(if_p); j++) { inet_addrinfo_t * info = if_inet_addr_at(if_p, j); printf("inet: %s", inet_ntoa(info->addr)); printf(" netmask %s", inet_ntoa(info->mask)); if (if_flags(if_p) & IFF_BROADCAST) printf(" %s\n", inet_ntoa(info->broadcast)); else printf("\n"); } if (if_p->link_address.type != 0) { link_addr_print(&if_p->link_address); if (if_p->link_status.valid) { printf("Link is %s%s\n", if_p->link_status.active ? "active" : "inactive", if_p->link_status.wake_on_same_network ? " [wake on same network]" : ""); } if (if_is_wireless(if_p)) { printf("wireless%s\n", if_is_awdl(if_p) ? " AWDL" : ""); } } count++; } return; }