summaryrefslogtreecommitdiffstats
path: root/crypto/openssh/openbsd-compat/fake-getaddrinfo.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/openssh/openbsd-compat/fake-getaddrinfo.c')
-rw-r--r--crypto/openssh/openbsd-compat/fake-getaddrinfo.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/crypto/openssh/openbsd-compat/fake-getaddrinfo.c b/crypto/openssh/openbsd-compat/fake-getaddrinfo.c
index 67e9eb7..e63bda9 100644
--- a/crypto/openssh/openbsd-compat/fake-getaddrinfo.c
+++ b/crypto/openssh/openbsd-compat/fake-getaddrinfo.c
@@ -12,7 +12,7 @@
#include "includes.h"
#include "ssh.h"
-RCSID("$Id: fake-getaddrinfo.c,v 1.2 2001/02/09 01:55:36 djm Exp $");
+RCSID("$Id: fake-getaddrinfo.c,v 1.5 2003/03/24 02:35:59 djm Exp $");
#ifndef HAVE_GAI_STRERROR
char *gai_strerror(int ecode)
@@ -67,16 +67,30 @@ int getaddrinfo(const char *hostname, const char *servname,
{
struct addrinfo *cur, *prev = NULL;
struct hostent *hp;
+ struct servent *sp;
struct in_addr in;
- int i, port;
+ int i;
+ long int port;
+ u_long addr;
- if (servname)
- port = htons(atoi(servname));
- else
- port = 0;
+ port = 0;
+ if (servname != NULL) {
+ char *cp;
+
+ port = strtol(servname, &cp, 10);
+ if (port > 0 && port <= 65535 && *cp == '\0')
+ port = htons(port);
+ else if ((sp = getservbyname(servname, NULL)) != NULL)
+ port = sp->s_port;
+ else
+ port = 0;
+ }
if (hints && hints->ai_flags & AI_PASSIVE) {
- if (NULL != (*res = malloc_ai(port, htonl(0x00000000))))
+ addr = htonl(0x00000000);
+ if (hostname && inet_aton(hostname, &in) != 0)
+ addr = in.s_addr;
+ if (NULL != (*res = malloc_ai(port, addr)))
return 0;
else
return EAI_MEMORY;
OpenPOWER on IntegriCloud