struct hostent * _door_gethostbyaddr_r(const char *addr, int length, int type, struct hostent *result, char *buffer, int buflen, int *h_errnop) { /* * allocate space on the stack for the nscd to return * host and host alias information */ union { nsc_data_t s_d; char s_b[8192]; } space; nsc_data_t *sptr; int ndata; int adata; struct hostent *resptr = NULL; if (addr == NULL) { if (h_errnop) *h_errnop = HOST_NOT_FOUND; return (NULL); } ndata = sizeof (space); adata = length + sizeof (nsc_call_t) + 1; sptr = &space.s_d; space.s_d.nsc_call.nsc_callnumber = GETHOSTBYADDR; space.s_d.nsc_call.nsc_u.addr.a_type = type; space.s_d.nsc_call.nsc_u.addr.a_length = length; (void) memcpy(space.s_d.nsc_call.nsc_u.addr.a_data, addr, length); switch (_nsc_trydoorcall(&sptr, &ndata, &adata)) { case SUCCESS: /* positive cache hit */ break; case NOTFOUND: /* negative cache hit */ if (h_errnop) *h_errnop = space.s_d.nsc_ret.nsc_errno; return (NULL); default: return ((struct hostent *)_switch_gethostbyaddr_r(addr, length, type, result, buffer, buflen, h_errnop)); } resptr = process_gethost(result, buffer, buflen, h_errnop, sptr); /* * check if doors realloced buffer underneath of us.... * munmap it or suffer a memory leak */ if (sptr != &space.s_d) { munmap((char *)sptr, ndata); /* return memory */ } return (resptr); }
struct hostent * _uncached_getipnodebyaddr(const char *addr, int length, int type, struct hostent *result, char *buffer, int buflen, int *h_errnop) { if (type == AF_INET) return (_switch_gethostbyaddr_r(addr, length, type, result, buffer, buflen, h_errnop)); else if (type == AF_INET6) return (_switch_getipnodebyaddr_r(addr, length, type, result, buffer, buflen, h_errnop)); return (NULL); }