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>
#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
struct netent *_getnetbyaddr __P((long net, int type));
-#if defined(sun)
-struct netent *_getnetbyname __P((char *name));
-#else
struct netent *_getnetbyname __P((const char *name));
-#endif
#define BYADDR 0
#define BYNAME 1
register u_char *cp;
register int n;
u_char *eom;
- int type, class, buflen, ancount, qdcount, haveanswer, i, nchar,
- getclass = C_ANY, net_length = 0;
+ int type, class, buflen, ancount, qdcount, haveanswer, i, nchar;
char aux1[30], aux2[30], ans[30], *in, *st, *pauxt, *bp, **ap,
*paux1 = &aux1[0], *paux2 = &aux2[0], flag = 0;
static struct netent net_entry;
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)
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';
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 =
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)
struct netent *
getnetbyname(net)
-#if defined(sun)
- register char *net;
-#else
register const char *net;
-#endif
{
- unsigned int netbr[4];
int anslen;
querybuf buf;
char qbuf[MAXDNAME];
struct netent *net_entry;
- strcpy(&qbuf[0],net);
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ __set_h_errno (NETDB_INTERNAL);
+ return (NULL);
+ }
+ strcpy(&qbuf[0], net);
anslen = res_search(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf));
if (anslen < 0) {
#ifdef DEBUG