]>
Commit | Line | Data |
---|---|---|
5545a732 JR |
1 | - IPv6 support to login command |
2 | ||
3 | --- util-linux-2.13-pre6/login-utils/login.c.ipv6 2006-10-12 10:10:34.000000000 +0200 | |
4 | +++ util-linux-2.13-pre6/login-utils/login.c 2006-10-12 10:17:16.000000000 +0200 | |
5 | @@ -173,7 +173,7 @@ | |
6 | #ifdef HAVE_SECURITY_PAM_MISC_H | |
7 | static struct passwd pwdcopy; | |
8 | #endif | |
9 | -char hostaddress[4]; /* used in checktty.c */ | |
10 | +char hostaddress[16]; /* used in checktty.c */ | |
11 | char *hostname; /* idem */ | |
12 | static char *username, *tty_name, *tty_number; | |
13 | static char thishost[100]; | |
14 | @@ -281,7 +281,7 @@ | |
15 | if (hostname) { | |
16 | xstrncpy(ut.ut_host, hostname, sizeof(ut.ut_host)); | |
17 | if (hostaddress[0]) | |
18 | - memcpy(&ut.ut_addr, hostaddress, sizeof(ut.ut_addr)); | |
19 | + memcpy(&ut.ut_addr_v6, hostaddress, sizeof(ut.ut_addr_v6)); | |
20 | } | |
21 | #if HAVE_UPDWTMP /* bad luck for ancient systems */ | |
22 | updwtmp(_PATH_BTMP, &ut); | |
23 | @@ -380,13 +380,33 @@ | |
24 | ||
25 | hostname = strdup(optarg); /* strdup: Ambrose C. Li */ | |
26 | { | |
27 | - struct hostent *he = gethostbyname(hostname); | |
28 | + struct addrinfo hints, *info = NULL; | |
29 | + | |
30 | + memset(&hints, '\0', sizeof(hints)); | |
31 | + hints.ai_flags = AI_ADDRCONFIG; | |
32 | + | |
33 | + hostaddress[0] = 0; | |
34 | ||
35 | - /* he points to static storage; copy the part we use */ | |
36 | - hostaddress[0] = 0; | |
37 | - if (he && he->h_addr_list && he->h_addr_list[0]) | |
38 | - memcpy(hostaddress, he->h_addr_list[0], | |
39 | - sizeof(hostaddress)); | |
40 | + if (getaddrinfo(hostname, NULL, &hints, &info)==0 && info) | |
41 | + { | |
42 | + if (info->ai_family == AF_INET) | |
43 | + { | |
44 | + struct sockaddr_in *sa4; | |
45 | + | |
46 | + sa4 = (struct sockaddr_in *) info->ai_addr; | |
47 | + memcpy(hostaddress, &(sa4->sin_addr), | |
48 | + sizeof(sa4->sin_addr)); | |
49 | + } | |
50 | + if (info->ai_family == AF_INET6) | |
51 | + { | |
52 | + struct sockaddr_in6 *sa6; | |
53 | + | |
54 | + sa6 = (struct sockaddr_in6 *) info->ai_addr; | |
55 | + memcpy(hostaddress, &(sa6->sin6_addr), | |
56 | + sizeof(sa6->sin6_addr)); | |
57 | + } | |
58 | + freeaddrinfo(info); | |
59 | + } | |
60 | } | |
61 | break; | |
62 | ||
63 | @@ -906,7 +926,7 @@ | |
64 | if (hostname) { | |
65 | xstrncpy(ut.ut_host, hostname, sizeof(ut.ut_host)); | |
66 | if (hostaddress[0]) | |
67 | - memcpy(&ut.ut_addr, hostaddress, sizeof(ut.ut_addr)); | |
68 | + memcpy(&ut.ut_addr_v6, hostaddress, sizeof(ut.ut_addr_v6)); | |
69 | } | |
70 | ||
71 | pututline(&ut); | |
72 | --- util-linux-2.13-pre6/login-utils/login.h.ipv6 2005-08-02 14:01:18.000000000 +0200 | |
73 | +++ util-linux-2.13-pre6/login-utils/login.h 2006-10-12 10:10:34.000000000 +0200 | |
74 | @@ -1,7 +1,7 @@ | |
75 | /* defined in login.c */ | |
76 | extern void badlogin(const char *s); | |
77 | extern void sleepexit(int); | |
78 | -extern char hostaddress[4]; | |
79 | +extern char hostaddress[16]; | |
80 | extern char *hostname; | |
81 | ||
82 | /* defined in checktty.c */ |