diff options
Diffstat (limited to 'openbsd-compat/fake-getaddrinfo.c')
-rw-r--r-- | openbsd-compat/fake-getaddrinfo.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/openbsd-compat/fake-getaddrinfo.c b/openbsd-compat/fake-getaddrinfo.c index 67e9eb788..bc58f30a6 100644 --- a/openbsd-compat/fake-getaddrinfo.c +++ b/openbsd-compat/fake-getaddrinfo.c | |||
@@ -12,7 +12,7 @@ | |||
12 | #include "includes.h" | 12 | #include "includes.h" |
13 | #include "ssh.h" | 13 | #include "ssh.h" |
14 | 14 | ||
15 | RCSID("$Id: fake-getaddrinfo.c,v 1.2 2001/02/09 01:55:36 djm Exp $"); | 15 | RCSID("$Id: fake-getaddrinfo.c,v 1.4.2.1 2003/03/26 05:03:06 djm Exp $"); |
16 | 16 | ||
17 | #ifndef HAVE_GAI_STRERROR | 17 | #ifndef HAVE_GAI_STRERROR |
18 | char *gai_strerror(int ecode) | 18 | char *gai_strerror(int ecode) |
@@ -67,16 +67,30 @@ int getaddrinfo(const char *hostname, const char *servname, | |||
67 | { | 67 | { |
68 | struct addrinfo *cur, *prev = NULL; | 68 | struct addrinfo *cur, *prev = NULL; |
69 | struct hostent *hp; | 69 | struct hostent *hp; |
70 | struct servent *sp; | ||
70 | struct in_addr in; | 71 | struct in_addr in; |
71 | int i, port; | 72 | int i; |
73 | long int port; | ||
74 | u_long addr; | ||
72 | 75 | ||
73 | if (servname) | 76 | port = 0; |
74 | port = htons(atoi(servname)); | 77 | if (servname != NULL) { |
75 | else | 78 | char *cp; |
76 | port = 0; | 79 | |
80 | port = strtol(servname, &cp, 10); | ||
81 | if (port > 0 && port <= 65535 && *cp == '\0') | ||
82 | port = htons(port); | ||
83 | else if ((sp = getservbyname(servname, NULL)) != NULL) | ||
84 | port = sp->s_port; | ||
85 | else | ||
86 | port = 0; | ||
87 | } | ||
77 | 88 | ||
78 | if (hints && hints->ai_flags & AI_PASSIVE) { | 89 | if (hints && hints->ai_flags & AI_PASSIVE) { |
79 | if (NULL != (*res = malloc_ai(port, htonl(0x00000000)))) | 90 | addr = htonl(0x00000000); |
91 | if (hostname && inet_aton(hostname, &in) != 0) | ||
92 | addr = in.s_addr; | ||
93 | if (NULL != (*res = malloc_ai(port, addr))) | ||
80 | return 0; | 94 | return 0; |
81 | else | 95 | else |
82 | return EAI_MEMORY; | 96 | return EAI_MEMORY; |