From 850b942037d527117a38d4e0350a5ee786020779 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Thu, 6 Feb 2003 10:50:42 +1100 Subject: - (djm) Teach fake-getaddrinfo to use getservbyname() when provided a string service name. Suggested by markus@, review by itojun@ --- ChangeLog | 6 +++++- openbsd-compat/fake-getaddrinfo.c | 24 +++++++++++++++++------- openbsd-compat/fake-getaddrinfo.h | 4 ++-- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index a6acb5c50..af9bf9a48 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +20030206 + - (djm) Teach fake-getaddrinfo to use getservbyname() when provided a + string service name. Suggested by markus@, review by itojun@ + 20030131 - (bal) AIX 4.2.1 lacks nanosleep(). Patch to use nsleep() provided by dtucker@zip.com.au @@ -1090,4 +1094,4 @@ save auth method before monitor_reset_key_state(); bugzilla bug #284; ok provos@ -$Id: ChangeLog,v 1.2591 2003/02/01 04:43:34 mouring Exp $ +$Id: ChangeLog,v 1.2592 2003/02/05 23:51:06 djm Exp $ diff --git a/openbsd-compat/fake-getaddrinfo.c b/openbsd-compat/fake-getaddrinfo.c index 67e9eb788..2a2f269cb 100644 --- a/openbsd-compat/fake-getaddrinfo.c +++ b/openbsd-compat/fake-getaddrinfo.c @@ -12,10 +12,10 @@ #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.3 2003/02/05 23:50:42 djm Exp $"); #ifndef HAVE_GAI_STRERROR -char *gai_strerror(int ecode) +const char *gai_strerror(int ecode) { switch (ecode) { case EAI_NODATA: @@ -67,13 +67,23 @@ 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; - 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)))) diff --git a/openbsd-compat/fake-getaddrinfo.h b/openbsd-compat/fake-getaddrinfo.h index afd0226e2..a14a2cc11 100644 --- a/openbsd-compat/fake-getaddrinfo.h +++ b/openbsd-compat/fake-getaddrinfo.h @@ -1,4 +1,4 @@ -/* $Id: fake-getaddrinfo.h,v 1.2 2001/02/09 01:55:36 djm Exp $ */ +/* $Id: fake-getaddrinfo.h,v 1.3 2003/02/05 23:50:43 djm Exp $ */ #ifndef _FAKE_GETADDRINFO_H #define _FAKE_GETADDRINFO_H @@ -37,7 +37,7 @@ int getaddrinfo(const char *hostname, const char *servname, #endif /* !HAVE_GETADDRINFO */ #ifndef HAVE_GAI_STRERROR -char *gai_strerror(int ecode); +const char *gai_strerror(int ecode); #endif /* !HAVE_GAI_STRERROR */ #ifndef HAVE_FREEADDRINFO -- cgit v1.2.3