util-linux/util-linux-2.13-login-ipv6....

81 lines
2.5 KiB
Diff

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