X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=libesmtp%2Fgetaddrinfo.c;h=5eaa0a68309974acf4c59d604ff934851f1641e4;hb=98cfcef26048bba06975e68a1aad05a8bac0d65d;hp=575b51d2019508a6fa42e1671a67861d1a1eab47;hpb=57fa56bcda740b4fb7aa09ca10fd685dd93574cd;p=~andy%2Ffetchmail diff --git a/libesmtp/getaddrinfo.c b/libesmtp/getaddrinfo.c index 575b51d2..5eaa0a68 100644 --- a/libesmtp/getaddrinfo.c +++ b/libesmtp/getaddrinfo.c @@ -27,6 +27,8 @@ #include #endif +#ifndef HAVE_GETADDRINFO + /* Need to turn off Posix features in glibc to build this */ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE @@ -89,26 +91,29 @@ getaddrinfo (const char *nodename, const char *servname, hints = &hint; } - /* servname must not be NULL in this implementation */ - if (servname == NULL) + if (servname == NULL && nodename == NULL) return EAI_NONAME; - /* check for tcp or udp sockets only */ - if (hints->ai_socktype == SOCK_STREAM) - socktype = "tcp"; - else if (hints->ai_socktype == SOCK_DGRAM) - socktype = "udp"; - else - return EAI_SERVICE; - result.ai_socktype = hints->ai_socktype; - - /* Note: maintain port in host byte order to make debugging easier */ - if (isdigit (*servname)) - port = strtol (servname, NULL, 10); - else if ((servent = getservbyname (servname, socktype)) != NULL) - port = ntohs (servent->s_port); - else - return EAI_NONAME; + if (servname == NULL) + port = 0; + else { + /* check for tcp or udp sockets only */ + if (hints->ai_socktype == SOCK_STREAM) + socktype = "tcp"; + else if (hints->ai_socktype == SOCK_DGRAM) + socktype = "udp"; + else + return EAI_SERVICE; + result.ai_socktype = hints->ai_socktype; + + /* Note: maintain port in host byte order to make debugging easier */ + if (isdigit (*servname)) + port = strtol (servname, NULL, 10); + else if ((servent = getservbyname (servname, socktype)) != NULL) + port = ntohs (servent->s_port); + else + return EAI_NONAME; + } /* if nodename == NULL refer to the local host for a client or any for a server */ @@ -305,6 +310,7 @@ gai_strerror (int ecode) "servname not supported for ai_socktype", /* EAI_SERVICE */ "ai_socktype not supported", /* EAI_SOCKTYPE */ "system error returned in errno", /* EAI_SYSTEM */ + "argument buffer overflow", /* EAI_OVERFLOW */ }; if (ecode < 0 || ecode > (int) (sizeof eai_descr/ sizeof eai_descr[0])) @@ -312,3 +318,4 @@ gai_strerror (int ecode) return eai_descr[ecode]; } +#endif