Aggiunto materiale vario sul resolver
[gapil.git] / listati / myhost.c
diff --git a/listati/myhost.c b/listati/myhost.c
new file mode 100644 (file)
index 0000000..0378058
--- /dev/null
@@ -0,0 +1,42 @@
+int main(int argc, char *argv[]) 
+{
+/* 
+ * Variables definition
+ */
+    int i;
+    struct hostent *data;
+    char **alias;
+    char *addr;
+    char buffer[INET6_ADDRSTRLEN];
+    ...
+    if ((argc - optind) != 1) {
+       printf("Wrong number of arguments %d\n", argc - optind);
+        usage();
+    }
+    data = gethostbyname(argv[1]);
+    if (data == NULL) {
+       herror("Errore di risoluzione");
+       exit(1);
+    }
+    printf("Canonical name %s\n", data->h_name);
+    alias = data->h_aliases;
+    while (*alias != NULL) {
+       printf("Alias %s\n", *alias);
+       alias++;
+    }
+    if (data->h_addrtype == AF_INET) {
+       printf("Address are IPv4\n");
+    } else if (data->h_addrtype == AF_INET6) {
+       printf("Address are IPv6\n");
+    } else {
+       printf("Tipo di indirizzo non valido\n");
+       exit(1);
+    }
+    alias = data->h_addr_list;
+    while (*alias != NULL) {
+       addr = inet_ntop(data->h_addrtype, *alias, buffer, sizeof(buffer));
+       printf("Indirizzo %s\n", addr);
+       alias++;
+    }    
+    exit(0);
+}