1999-03-07 Mark Kettenis <kettenis@gnu.org>
[kopensolaris-gnu/glibc.git] / resolv / getnetnamadr.c
index e5cc505..abbc3a3 100644 (file)
@@ -44,6 +44,7 @@ static char sccsid_[] = "from getnetnamadr.c  1.4 (Coimbra) 93/06/03";
 static char rcsid[] = "$Id$";
 #endif /* LIBC_SCCS and not lint */
 
+#include <sys/types.h>
 #include <sys/param.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -57,9 +58,11 @@ static char rcsid[] = "$Id$";
 #include <errno.h>
 #include <string.h>
 
+#ifndef h_errno
 extern int h_errno;
+#endif
 
-#if defined(mips) && defined(SYSTYPE_BSD43)
+#if defined(mips) && defined(SYSTYPE_BSD43) && !defined(errno)
 extern int errno;
 #endif
 
@@ -126,9 +129,9 @@ static      char *net_aliases[MAXALIASES], netbuf[BUFSIZ+1];
        cp = answer->buf + HFIXEDSZ;
        if (!qdcount) {
                if (hp->aa)
-                       h_errno = HOST_NOT_FOUND;
+                       __set_h_errno (HOST_NOT_FOUND);
                else
-                       h_errno = TRY_AGAIN;
+                       __set_h_errno (TRY_AGAIN);
                return (NULL);
        }
        while (qdcount-- > 0)
@@ -139,7 +142,7 @@ static      char *net_aliases[MAXALIASES], netbuf[BUFSIZ+1];
        haveanswer = 0;
        while (--ancount >= 0 && cp < eom) {
                n = dn_expand(answer->buf, eom, cp, bp, buflen);
-               if (n < 0)
+               if ((n < 0) || !res_dnok(bp))
                        break;
                cp += n;
                ans[0] = '\0';
@@ -150,11 +153,11 @@ static    char *net_aliases[MAXALIASES], netbuf[BUFSIZ+1];
                GETSHORT(n, cp);
                if (class == C_IN && type == T_PTR) {
                        n = dn_expand(answer->buf, eom, cp, bp, buflen);
-                       if (n < 0) {
+                       if ((n < 0) || !res_hnok(bp)) {
                                cp += n;
                                return (NULL);
                        }
-                       cp += n; 
+                       cp += n;
                        *ap++ = bp;
                        bp += strlen(bp) + 1;
                        net_entry.n_addrtype =
@@ -189,27 +192,27 @@ static    char *net_aliases[MAXALIASES], netbuf[BUFSIZ+1];
                                        paux1 = pauxt;
                                }
                                in = ++st;
-                       }                 
+                       }
                        net_entry.n_net = inet_network(paux2);
                        break;
                }
                net_entry.n_aliases++;
                return (&net_entry);
        }
-       h_errno = TRY_AGAIN;
+       __set_h_errno (TRY_AGAIN);
        return (NULL);
 }
 
 struct netent *
 getnetbyaddr(net, net_type)
-       register long net;
+       register u_long net;
        register int net_type;
 {
        unsigned int netbr[4];
        int nn, anslen;
        querybuf buf;
        char qbuf[MAXDNAME];
-       unsigned long net2;
+       u_int32_t net2;         /* Changed from unsigned long --roland */
        struct netent *net_entry;
 
        if (net_type != AF_INET)
@@ -266,7 +269,7 @@ getnetbyname(net)
        struct netent *net_entry;
 
        if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
-               h_errno = NETDB_INTERNAL;
+               __set_h_errno (NETDB_INTERNAL);
                return (NULL);
        }
        strcpy(&qbuf[0], net);