diff --git a/Makefile b/Makefile
index 73e08e2..ac52007 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-CFLAGS=-O2 -Wall
+CFLAGS+=-O2 -Wall
 
 # uncomment the following line if you want to install to a different base dir.
 #BASEDIR=/mnt/test
diff --git a/hostname b/hostname
index 31b651b..ba80ce3 100755
Binary files a/hostname and b/hostname differ
diff --git a/hostname.1 b/hostname.1
index fccd845..c196ed4 100644
--- a/hostname.1
+++ b/hostname.1
@@ -1,4 +1,4 @@
-.TH HOSTNAME 1 "28 Jan 1996" "net-tools" "Linux Programmer's Manual"
+.TH HOSTNAME 1 "2009-08-06" "net-tools" "Linux Programmer's Manual"
 
 .SH NAME
 hostname \- show or set the system's host name
@@ -94,7 +94,7 @@ with this command. The FQDN of the system is the name that the
 returns for the host name.
 .LP
 Technically: The FQDN is the name
-.BR gethostbyname (2)
+.BR getaddrinfo (3)
 returns for the host name returned by
 .BR gethostname (2).
 The DNS domain name is the part after the first dot.
@@ -108,7 +108,8 @@ NIS) you can change it in
 .SH OPTIONS
 .TP
 .I "\-a, \-\-alias"
-Display the alias name of the host (if used).
+Display the alias name of the host (if used). This option is ignored and
+available for backwards compatibility only.
 .TP
 .I "\-d, \-\-domain"
 Display the name of the DNS domain.  Don't use the command
diff --git a/hostname.c b/hostname.c
index 23915de..fe39c79 100644
--- a/hostname.c
+++ b/hostname.c
@@ -198,9 +198,10 @@ set_name(enum type_t type, char *name)
 void
 show_name(enum type_t type)
 {
-	struct hostent *hp;
+	struct addrinfo *res;
+	struct addrinfo hints;
 	char *p;
-	int i;
+	int ret;
 
 	/* Handle a few cases specially. */
 	if (type == DEFAULT) {
@@ -211,30 +212,32 @@ show_name(enum type_t type)
 		return;
 	}
 
-	/* Otherwise, resolve the host name to get more information. */
-	if ((hp = gethostbyname(localhost())) == NULL)
-		errx(1, "%s", hstrerror(h_errno));
+	memset(&hints, 0, sizeof(struct addrinfo));
+	hints.ai_socktype = SOCK_DGRAM;
+	hints.ai_flags = AI_CANONNAME;
 
-	p = strchr(hp->h_name, '.');
+	if ((ret = getaddrinfo(localhost(), NULL, &hints, &res)) != 0)
+		errx(1, "%s", gai_strerror(ret));
 
-	switch (type) {
-	case ALIAS:
-		for (i = 0; hp->h_aliases[i]; i++) {
-			if (i > 0)
-				printf(" ");
-			printf("%s ", hp->h_aliases[i]);
-		}
-		printf("\n");
-		break;
+	p = strchr(res->ai_canonname, '.');
 
+	switch (type) {
 	case IP: {
 		char buf[INET6_ADDRSTRLEN];
+		int ret;
+
+		struct addrinfo *walk;
 
-		for (i = 0; hp->h_addr_list[i]; i++) {
-			if (i > 0)
+		for (walk = res; walk != NULL; walk = walk->ai_next) {
+			if ((ret = getnameinfo(walk->ai_addr, walk->ai_addrlen,
+						buf, sizeof(buf), NULL, 0,
+						NI_NUMERICHOST)) != 0)
+				errx(1, "%s", gai_strerror(ret));
+
+			if (walk != res)
 				printf(" ");
-			printf("%s", inet_ntop(hp->h_addrtype,
-			       hp->h_addr_list[i], buf, sizeof(buf)));
+
+			printf("%s", buf);
 		}
 		printf("\n");
 		break;
@@ -246,13 +249,13 @@ show_name(enum type_t type)
 		break;
 
 	case FQDN:
-		printf("%s\n", hp->h_name);
+		printf("%s\n", res->ai_canonname);
 		break;
 
 	case SHORT:
 		if (p != NULL)
 			*p = '\0';
-		printf("%s\n", hp->h_name);
+		printf("%s\n", res->ai_canonname);
 		break;
 
 	default:
diff --git a/hostname.o b/hostname.o
index 1f90a7f..dec246d 100644
Binary files a/hostname.o and b/hostname.o differ
