]> andersk Git - gssapi-openssh.git/blobdiff - openssh/openbsd-compat/fake-getaddrinfo.c
Import of OpenSSH 3.6.1p1
[gssapi-openssh.git] / openssh / openbsd-compat / fake-getaddrinfo.c
index 5a1ad972a5f42cf4a467adf104cada6b2493bb7a..0eb2f4b3f0a589d4b1b16fa6523edb8dd63042a6 100644 (file)
@@ -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;
This page took 0.036256 seconds and 4 git commands to generate.