mschorm / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
4f8c2f9
--- util-linux-2.13-pre6/login-utils/login.c.ipv6	2006-07-17 11:05:48.000000000 +0200
4f8c2f9
+++ util-linux-2.13-pre6/login-utils/login.c	2006-07-17 11:05:48.000000000 +0200
4f8c2f9
@@ -173,7 +173,7 @@
4f8c2f9
 #ifdef HAVE_SECURITY_PAM_MISC_H
4f8c2f9
 static struct passwd pwdcopy;
4f8c2f9
 #endif
4f8c2f9
-char    hostaddress[4];		/* used in checktty.c */
4f8c2f9
+char    hostaddress[16];	/* used in checktty.c */
4f8c2f9
 char	*hostname;		/* idem */
4f8c2f9
 static char	*username, *tty_name, *tty_number;
4f8c2f9
 static char	thishost[100];
4f8c2f9
@@ -281,7 +281,7 @@
4f8c2f9
 	if (hostname) {
4f8c2f9
 		xstrncpy(ut.ut_host, hostname, sizeof(ut.ut_host));
4f8c2f9
 		if (hostaddress[0])
4f8c2f9
-			memcpy(&ut.ut_addr, hostaddress, sizeof(ut.ut_addr));
4f8c2f9
+			memcpy(&ut.ut_addr_v6, hostaddress, sizeof(ut.ut_addr_v6));
4f8c2f9
 	}
4f8c2f9
 #if HAVE_UPDWTMP		/* bad luck for ancient systems */
4f8c2f9
 	updwtmp(_PATH_BTMP, &ut);
4f8c2f9
@@ -380,13 +380,32 @@
4f8c2f9
 
4f8c2f9
 	  hostname = strdup(optarg); 	/* strdup: Ambrose C. Li */
4f8c2f9
 	  {
4f8c2f9
-		  struct hostent *he = gethostbyname(hostname);
4f8c2f9
+		struct addrinfo hints, *addr_info;
4f8c2f9
+		int k=0;
4f8c2f9
+		
4f8c2f9
+		memset(&hints, '\0', sizeof(hints));
4f8c2f9
+		hints.ai_flags = AI_ADDRCONFIG;
4f8c2f9
+		
4f8c2f9
+		if (getaddrinfo(hostname, NULL, &hints, &addr_info) != 0)
4f8c2f9
+		    fprintf(stderr, "getaddrinfo: %s\n", strerror(errno));
4f8c2f9
+
4f8c2f9
+		hostaddress[0] = 0;
4f8c2f9
 
4f8c2f9
-		  /* he points to static storage; copy the part we use */
4f8c2f9
-		  hostaddress[0] = 0;
4f8c2f9
-		  if (he && he->h_addr_list && he->h_addr_list[0])
4f8c2f9
-			  memcpy(hostaddress, he->h_addr_list[0],
4f8c2f9
-				 sizeof(hostaddress));
4f8c2f9
+		if (addr_info && (addr_info->ai_family == AF_INET))
4f8c2f9
+		{
4f8c2f9
+		    struct sockaddr_in *sa4;
4f8c2f9
+		    
4f8c2f9
+		    sa4 = (struct sockaddr_in *)addr_info->ai_addr;
4f8c2f9
+		    memcpy(hostaddress, &(sa4->sin_addr), sizeof(sa4->sin_addr));
4f8c2f9
+		}
4f8c2f9
+		if (addr_info && (addr_info->ai_family == AF_INET6))
4f8c2f9
+		{
4f8c2f9
+		    struct sockaddr_in6 *sa6;
4f8c2f9
+		    
4f8c2f9
+		    sa6 = (struct sockaddr_in6 *)addr_info->ai_addr;
4f8c2f9
+		    memcpy(hostaddress, &(sa6->sin6_addr), sizeof(sa6->sin6_addr));
4f8c2f9
+		}
4f8c2f9
+		freeaddrinfo(addr_info);
4f8c2f9
 	  }
4f8c2f9
 	  break;
4f8c2f9
 	  
4f8c2f9
@@ -906,7 +925,7 @@
4f8c2f9
 	if (hostname) {
4f8c2f9
 		xstrncpy(ut.ut_host, hostname, sizeof(ut.ut_host));
4f8c2f9
 		if (hostaddress[0])
4f8c2f9
-			memcpy(&ut.ut_addr, hostaddress, sizeof(ut.ut_addr));
4f8c2f9
+			memcpy(&ut.ut_addr_v6, hostaddress, sizeof(ut.ut_addr_v6));
4f8c2f9
 	}
4f8c2f9
 	
4f8c2f9
 	pututline(&ut);
4f8c2f9
--- util-linux-2.13-pre6/login-utils/login.h.ipv6	2005-08-02 14:01:18.000000000 +0200
4f8c2f9
+++ util-linux-2.13-pre6/login-utils/login.h	2006-07-17 11:05:48.000000000 +0200
4f8c2f9
@@ -1,7 +1,7 @@
4f8c2f9
 /* defined in login.c */
4f8c2f9
 extern void badlogin(const char *s);
4f8c2f9
 extern void sleepexit(int);
4f8c2f9
-extern char hostaddress[4];
4f8c2f9
+extern char hostaddress[16];
4f8c2f9
 extern char *hostname;
4f8c2f9
 
4f8c2f9
 /* defined in checktty.c */