int _ht_getnetbyname(void *rval, void *cb_data, va_list ap) { const char *name; char *buffer; size_t buflen; int *errnop, *h_errnop; struct netent *nptr, ne; struct netent_data *ned; char **cp; res_state statp; int error; name = va_arg(ap, const char *); nptr = va_arg(ap, struct netent *); buffer = va_arg(ap, char *); buflen = va_arg(ap, size_t); errnop = va_arg(ap, int *); h_errnop = va_arg(ap, int *); statp = __res_state(); if ((ned = __netent_data_init()) == NULL) { RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; return (NS_UNAVAIL); } _setnethtent(ned->stayopen, ned); while ((error = getnetent_p(&ne, ned)) == 0) { if (strcasecmp(ne.n_name, name) == 0) break; for (cp = ne.n_aliases; *cp != 0; cp++) if (strcasecmp(*cp, name) == 0) goto found; } found: if (!ned->stayopen) _endnethtent(ned); if (error != 0) { *h_errnop = statp->res_h_errno; return (NS_NOTFOUND); } if (__copy_netent(&ne, nptr, buffer, buflen) != 0) { *errnop = errno; RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; return (NS_RETURN); } *((struct netent **)rval) = nptr; return (NS_SUCCESS); }
int _ht_getnetbyaddr(void *rval, void *cb_data, va_list ap) { uint32_t net; int type; char *buffer; size_t buflen; int *errnop, *h_errnop; struct netent *nptr, ne; struct netent_data *ned; res_state statp; int error; net = va_arg(ap, uint32_t); type = va_arg(ap, int); nptr = va_arg(ap, struct netent *); buffer = va_arg(ap, char *); buflen = va_arg(ap, size_t); errnop = va_arg(ap, int *); h_errnop = va_arg(ap, int *); statp = __res_state(); if ((ned = __netent_data_init()) == NULL) { RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; return (NS_UNAVAIL); } _setnethtent(ned->stayopen, ned); while ((error = getnetent_p(&ne, ned)) == 0) if (ne.n_addrtype == type && ne.n_net == net) break; if (!ned->stayopen) _endnethtent(ned); if (error != 0) { *h_errnop = statp->res_h_errno; return (NS_NOTFOUND); } if (__copy_netent(&ne, nptr, buffer, buflen) != 0) { *errnop = errno; RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; return (NS_RETURN); } *((struct netent **)rval) = nptr; return (NS_SUCCESS); }
int _nis_getnetbyname(void *rval, void *cb_data, va_list ap) { #ifdef YP const char *name; char *buffer; size_t buflen; int *errnop, *h_errnop; struct netent *nptr, ne; struct netent_data *ned; res_state statp; name = va_arg(ap, const char *); nptr = va_arg(ap, struct netent *); buffer = va_arg(ap, char *); buflen = va_arg(ap, size_t); errnop = va_arg(ap, int *); h_errnop = va_arg(ap, int *); statp = __res_state(); if ((ned = __netent_data_init()) == NULL) { RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; return (NS_UNAVAIL); } if (_getnetbynis(name, "networks.byname", AF_INET, &ne, ned) != 0) { *h_errnop = statp->res_h_errno; return (NS_NOTFOUND); } if (__copy_netent(&ne, nptr, buffer, buflen) != 0) { *errnop = errno; RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; return (NS_RETURN); } *((struct netent **)rval) = nptr; return (NS_SUCCESS); #else return (NS_UNAVAIL); #endif }
int getnetent_r(struct netent *nptr, char *buffer, size_t buflen, struct netent **result, int *h_errnop) { struct netent_data *ned; struct netent ne; res_state statp; statp = __res_state(); if ((ned = __netent_data_init()) == NULL) { RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; return (-1); } if (getnetent_p(&ne, ned) != 0) return (-1); if (__copy_netent(&ne, nptr, buffer, buflen) != 0) return (-1); *result = nptr; return (0); }
int _nis_getnetbyaddr(void *rval, void *cb_data, va_list ap) { #ifdef YP uint32_t addr; int af; char *buffer; size_t buflen; int *errnop, *h_errnop; struct netent *nptr, ne; struct netent_data *ned; char *str, *cp; uint32_t net2; int nn; unsigned int netbr[4]; char buf[MAXDNAME]; res_state statp; addr = va_arg(ap, uint32_t); af = va_arg(ap, int); nptr = va_arg(ap, struct netent *); buffer = va_arg(ap, char *); buflen = va_arg(ap, size_t); errnop = va_arg(ap, int *); h_errnop = va_arg(ap, int *); statp = __res_state(); if ((ned = __netent_data_init()) == NULL) { RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; return (NS_UNAVAIL); } if (af != AF_INET) { RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; errno = EAFNOSUPPORT; return (NS_UNAVAIL); } for (nn = 4, net2 = addr; net2; net2 >>= 8) { netbr[--nn] = net2 & 0xff; } switch (nn) { case 3: /* Class A */ sprintf(buf, "%u", netbr[3]); break; case 2: /* Class B */ sprintf(buf, "%u.%u", netbr[2], netbr[3]); break; case 1: /* Class C */ sprintf(buf, "%u.%u.%u", netbr[1], netbr[2], netbr[3]); break; case 0: /* Class D - E */ sprintf(buf, "%u.%u.%u.%u", netbr[0], netbr[1], netbr[2], netbr[3]); break; } str = (char *)&buf; cp = str + (strlen(str) - 2); while(!strcmp(cp, ".0")) { *cp = '\0'; cp = str + (strlen(str) - 2); } if (_getnetbynis(str, "networks.byaddr", af, &ne, ned) != 0) { *h_errnop = statp->res_h_errno; return (NS_NOTFOUND); } if (__copy_netent(&ne, nptr, buffer, buflen) != 0) { *errnop = errno; RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; return (NS_RETURN); } *((struct netent **)rval) = nptr; return (NS_SUCCESS); #else return (NS_UNAVAIL); #endif /* YP */ }