enum nss_status _nss_dns_getnetbyname_r (const char *name, struct netent *result, char *buffer, size_t buflen, int *errnop, int *herrnop) { /* Return entry for network with NAME. */ union { querybuf *buf; u_char *ptr; } net_buffer; querybuf *orig_net_buffer; int anslen; enum nss_status status; struct resolv_context *ctx = __resolv_context_get (); if (ctx == NULL) { *errnop = errno; *herrnop = NETDB_INTERNAL; return NSS_STATUS_UNAVAIL; } net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024); anslen = __res_context_search (ctx, name, C_IN, T_PTR, net_buffer.buf->buf, 1024, &net_buffer.ptr, NULL, NULL, NULL, NULL); if (anslen < 0) { /* Nothing found. */ *errnop = errno; if (net_buffer.buf != orig_net_buffer) free (net_buffer.buf); __resolv_context_put (ctx); return (errno == ECONNREFUSED || errno == EPFNOSUPPORT || errno == EAFNOSUPPORT) ? NSS_STATUS_UNAVAIL : NSS_STATUS_NOTFOUND; } status = getanswer_r (net_buffer.buf, anslen, result, buffer, buflen, errnop, herrnop, BYNAME); if (net_buffer.buf != orig_net_buffer) free (net_buffer.buf); __resolv_context_put (ctx); return status; }
enum nss_status _nss_dns_getnetbyname_r (const char *name, struct netent *result, char *buffer, size_t buflen, int *errnop, int *herrnop) { /* Return entry for network with NAME. */ union { querybuf *buf; u_char *ptr; } net_buffer; querybuf *orig_net_buffer; int anslen; char *qbuf; enum nss_status status; if (__res_maybe_init (&_res, 0) == -1) return NSS_STATUS_UNAVAIL; qbuf = strdupa (name); net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024); anslen = __libc_res_nsearch (&_res, qbuf, C_IN, T_PTR, net_buffer.buf->buf, 1024, &net_buffer.ptr, NULL, NULL, NULL, NULL); if (anslen < 0) { /* Nothing found. */ *errnop = errno; if (net_buffer.buf != orig_net_buffer) free (net_buffer.buf); return (errno == ECONNREFUSED || errno == EPFNOSUPPORT || errno == EAFNOSUPPORT) ? NSS_STATUS_UNAVAIL : NSS_STATUS_NOTFOUND; } status = getanswer_r (net_buffer.buf, anslen, result, buffer, buflen, errnop, herrnop, BYNAME); if (net_buffer.buf != orig_net_buffer) free (net_buffer.buf); return status; }
enum nss_status _nss_dns_getnetbyaddr_r (uint32_t net, int type, struct netent *result, char *buffer, size_t buflen, int *errnop, int *herrnop) { /* Return entry for network with NAME. */ enum nss_status status; union { querybuf *buf; u_char *ptr; } net_buffer; querybuf *orig_net_buffer; unsigned int net_bytes[4]; char qbuf[MAXDNAME]; int cnt, anslen; u_int32_t net2; int olderr = errno; /* No net address lookup for IPv6 yet. */ if (type != AF_INET) return NSS_STATUS_UNAVAIL; if (__res_maybe_init (&_res, 0) == -1) return NSS_STATUS_UNAVAIL; net2 = (u_int32_t) net; for (cnt = 4; net2 != 0; net2 >>= 8) net_bytes[--cnt] = net2 & 0xff; switch (cnt) { case 3: /* Class A network. */ sprintf (qbuf, "0.0.0.%u.in-addr.arpa", net_bytes[3]); break; case 2: /* Class B network. */ sprintf (qbuf, "0.0.%u.%u.in-addr.arpa", net_bytes[3], net_bytes[2]); break; case 1: /* Class C network. */ sprintf (qbuf, "0.%u.%u.%u.in-addr.arpa", net_bytes[3], net_bytes[2], net_bytes[1]); break; case 0: /* Class D - E network. */ sprintf (qbuf, "%u.%u.%u.%u.in-addr.arpa", net_bytes[3], net_bytes[2], net_bytes[1], net_bytes[0]); break; } net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024); anslen = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR, net_buffer.buf->buf, 1024, &net_buffer.ptr, NULL, NULL, NULL, NULL); if (anslen < 0) { /* Nothing found. */ int err = errno; __set_errno (olderr); if (net_buffer.buf != orig_net_buffer) free (net_buffer.buf); return (err == ECONNREFUSED || err == EPFNOSUPPORT || err == EAFNOSUPPORT) ? NSS_STATUS_UNAVAIL : NSS_STATUS_NOTFOUND; } status = getanswer_r (net_buffer.buf, anslen, result, buffer, buflen, errnop, herrnop, BYADDR); if (net_buffer.buf != orig_net_buffer) free (net_buffer.buf); if (status == NSS_STATUS_SUCCESS) { /* Strip trailing zeros. */ unsigned int u_net = net; /* Maybe net should be unsigned? */ while ((u_net & 0xff) == 0 && u_net != 0) u_net >>= 8; result->n_net = u_net; }