- u_int32_t split[4];
- u_int32_t ip;
-
- sscanf(addr, "%d.%d.%d.%d",
- &split[0], &split[1], &split[2], &split[3]);
-
- /* assuming sscanf worked */
- ip = (split[0] << 24) |
- (split[1] << 16) | (split[2] << 8) | (split[3]);
-
- return htonl(ip);
-}
-
-/* takes the NULL-terminated array h_addr_list, and
- * prints its contents appropriately
- */
-static int addr_list_fprint(char **h_addr_list)
-{
- int i, j;
- char *addr_string = (h_addr_list[1])
- ? "Addresses: " : "Address: ";
-
- printf("%s ", addr_string);
- for (i = 0, j = 0; h_addr_list[i]; i++, j++) {
- addr_fprint(h_addr_list[i]);
-
- /* real nslookup does this */
- if (j == 4) {
- if (h_addr_list[i + 1]) {
- printf("\n ");
- }
- j = 0;
- } else {
- if (h_addr_list[i + 1]) {
- printf(", ");
+ /* We can't use xhost2sockaddr() - we want to get ALL addresses,
+ * not just one */
+ struct addrinfo *result = NULL;
+ int rc;
+ struct addrinfo hint;
+
+ memset(&hint, 0 , sizeof(hint));
+ /* hint.ai_family = AF_UNSPEC; - zero anyway */
+ /* Needed. Or else we will get each address thrice (or more)
+ * for each possible socket type (tcp,udp,raw...): */
+ hint.ai_socktype = SOCK_STREAM;
+ // hint.ai_flags = AI_CANONNAME;
+ rc = getaddrinfo(hostname, NULL /*service*/, &hint, &result);
+
+ if (rc == 0) {
+ struct addrinfo *cur = result;
+ unsigned cnt = 0;
+
+ printf("%-10s %s\n", header, hostname);
+ // puts(cur->ai_canonname); ?
+ while (cur) {
+ char *dotted, *revhost;
+ dotted = xmalloc_sockaddr2dotted_noport(cur->ai_addr);
+ revhost = xmalloc_sockaddr2hostonly_noport(cur->ai_addr);
+
+ printf("Address %u: %s%c", ++cnt, dotted, revhost ? ' ' : '\n');
+ if (revhost) {
+ puts(revhost);
+ if (ENABLE_FEATURE_CLEAN_UP)
+ free(revhost);