const char * print_address (const ip_address *addr) { static char buf[64]; if (!inet_ntop (addr->family, IP_INADDR_DATA (addr), buf, sizeof buf)) snprintf (buf, sizeof buf, "<error: %s>", strerror (errno)); return buf; }
const char * print_address (const ip_address *addr) { #ifdef ENABLE_IPV6 static char buf[64]; if (!inet_ntop (addr->family, IP_INADDR_DATA (addr), buf, sizeof buf)) snprintf (buf, sizeof buf, "<error: %s>", strerror (errno)); return buf; #else return inet_ntoa (addr->data.d4); #endif }
static struct address_list * address_list_from_ipv4_addresses (char **vec) { int count, i; struct address_list *al = xnew0 (struct address_list); count = 0; while (vec[count]) ++count; assert (count > 0); al->addresses = xnew_array (ip_address, count); al->count = count; al->refcount = 1; for (i = 0; i < count; i++) { ip_address *ip = &al->addresses[i]; ip->family = AF_INET; memcpy (IP_INADDR_DATA (ip), vec[i], 4); } return al; }
static struct address_list * address_list_from_hostent (struct hostent *host) { int count, i; struct address_list *al = xnew0 (struct address_list); for (count = 0; host->h_addr_list[count]; count++) ; assert (count > 0); al->addresses = xnew_array (ip_address, count); al->count = count; al->refcount = 1; for (i = 0; i < count; i++) { ip_address *ip = &al->addresses[i]; ip->family = host->h_addrtype; memcpy (IP_INADDR_DATA (ip), host->h_addr_list[i], ip->family == AF_INET ? 4 : 16); } return al; }