strcpy(qp, "ip6.int");
strcpy(qp, "ip6.arpa");
gethostbyaddr(addr, len, af)	const void *addr;	socklen_t len;	int af;{	const u_char *uaddr = (const u_char *)addr;	static const u_char mapped[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0xff,0xff };	static const u_char tunnelled[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 };	int n, size;	querybuf buf;	register struct hostent *hp;	char qbuf[MAXDNAME+1], *qp;#ifdef SUNSECURITY	register struct hostent *rhp;	char **haddr;	u_long old_options;	char hname2[MAXDNAME+1];#endif /*SUNSECURITY*/	extern struct hostent *_gethtbyaddr();	if ((_res.options & RES_INIT) == 0 && __res_ninit(&_res) == -1) {		__set_h_errno (NETDB_INTERNAL);		return (NULL);	}	if (af == AF_INET6 && len == IN6ADDRSZ &&	    (!bcmp(uaddr, mapped, sizeof mapped) ||	     !bcmp(uaddr, tunnelled, sizeof tunnelled))) {		/* Unmap. */		addr += sizeof mapped;		uaddr += sizeof mapped;		af = AF_INET;		len = INADDRSZ;	}	switch (af) {	case AF_INET:		size = INADDRSZ;		break;	case AF_INET6:		size = IN6ADDRSZ;		break;	default:		__set_errno (EAFNOSUPPORT);		__set_h_errno (NETDB_INTERNAL);		return (NULL);	}	if (size != len) {		__set_errno (EINVAL);		__set_h_errno (NETDB_INTERNAL);		return (NULL);	}	switch (af) {	case AF_INET:		(void) sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa",			       (uaddr[3] & 0xff),			       (uaddr[2] & 0xff),			       (uaddr[1] & 0xff),			       (uaddr[0] & 0xff));		break;	case AF_INET6:		qp = qbuf;		for (n = IN6ADDRSZ - 1; n >= 0; n--) {			qp += SPRINTF((qp, "%x.%x.",				       uaddr[n] & 0xf,				       (uaddr[n] >> 4) & 0xf));		}		strcpy(qp, "ip6.int");		break;	default:		abort();	}	n = res_nquery(&_res, qbuf, C_IN, T_PTR, (u_char *)buf.buf, sizeof buf.buf);	if (n < 0) {		dprintf("res_nquery failed (%d)\n", n);		if (errno == ECONNREFUSED)			return (_gethtbyaddr(addr, len, af));		return (NULL);	}	if (!(hp = getanswer(&buf, n, qbuf, T_PTR)))		return (NULL);	/* h_errno was set by getanswer() */#ifdef SUNSECURITY	if (af == AF_INET) {	    /*	     * turn off search as the name should be absolute,	     * 'localhost' should be matched by defnames	     */	    strncpy(hname2, hp->h_name, MAXDNAME);	    hname2[MAXDNAME] = '\0';	    old_options = _res.options;	    _res.options &= ~RES_DNSRCH;	    _res.options |= RES_DEFNAMES;	    if (!(rhp = gethostbyname(hname2))) {		syslog(LOG_NOTICE|LOG_AUTH,		       "gethostbyaddr: No A record for %s (verifying [%s])",		       hname2, inet_ntoa(*((struct in_addr *)addr)));		_res.options = old_options;		__set_h_errno (HOST_NOT_FOUND);		return (NULL);	    }	    _res.options = old_options;	    for (haddr = rhp->h_addr_list; *haddr; haddr++)		if (!memcmp(*haddr, addr, INADDRSZ))			break;	    if (!*haddr) {		syslog(LOG_NOTICE|LOG_AUTH,		       "gethostbyaddr: A record of %s != PTR record [%s]",		       hname2, inet_ntoa(*((struct in_addr *)addr)));		__set_h_errno (HOST_NOT_FOUND);		return (NULL);	    }	}#endif /*SUNSECURITY*/	hp->h_addrtype = af;	hp->h_length = len;	memmove(host_addr, addr, len);	h_addr_ptrs[0] = (char *)host_addr;	h_addr_ptrs[1] = NULL;	if (af == AF_INET && (_res.options & RES_USE_INET6)) {		map_v4v6_address((char*)host_addr, (char*)host_addr);		hp->h_addrtype = AF_INET6;		hp->h_length = IN6ADDRSZ;	}	__set_h_errno (NETDB_SUCCESS);	return (hp);}