⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resolver.c

📁 bind-3.2.
💻 C
📖 第 1 页 / 共 2 页
字号:
}#endif#ifdef HAVE_GETHOSTBYNAMEstruct hostent *ENTRY(gethostbyname)(const char *name) {	static hostbuf_t buf;	static struct hostent he;	idn_result_t r;	struct hostent *hp;	if (idn_isprocessing)		return (REAL(gethostbyname)(name));	TRACE(("gethostbyname(name=%s)\n", idn__debug_xstring(name, 60)));	idn_isprocessing = 1;	idn_enable(1);	idn_nameinit(1);	r = idn_encodename(IDN_ENCODE_APP, name, buf.data, sizeof(buf));	if (r == idn_success)		name = buf.data;	hp = copy_decode_hostent_static(REAL(gethostbyname)(name),					&he, buf.data, sizeof(buf),					&h_errno);	idn_isprocessing = 0;	return (hp);}#endif#ifdef HAVE_GETHOSTBYNAME2struct hostent *ENTRY(gethostbyname2)(const char *name, int af) {	static hostbuf_t buf;	static struct hostent he;	idn_result_t r;	struct hostent *hp;	if (idn_isprocessing)		return (REAL(gethostbyname2)(name, af));	TRACE(("gethostbyname2(name=%s)\n", idn__debug_xstring(name, 60), af));	idn_isprocessing = 1;	idn_enable(1);	idn_nameinit(1);	r = idn_encodename(IDN_ENCODE_APP, name, buf.data, sizeof(buf));	if (r == idn_success)		name = buf.data;	hp = copy_decode_hostent_static(REAL(gethostbyname2)(name, af),					&he, buf.data, sizeof(buf),					&h_errno);	idn_isprocessing = 0;	return (hp);}#endif#ifdef HAVE_GETHOSTBYADDRstruct hostent *ENTRY(gethostbyaddr)(GHBA_ADDR_T addr, GHBA_ADDRLEN_T len, int type) {	static hostbuf_t buf;	static struct hostent he;	struct hostent *hp;	if (idn_isprocessing)		return (REAL(gethostbyaddr)(addr, len, type));	TRACE(("gethostbyaddr()\n"));	idn_isprocessing = 1;	hp = copy_decode_hostent_static(REAL(gethostbyaddr)(addr, len, type),					&he, buf.data, sizeof(buf),					&h_errno);	idn_isprocessing = 0;	return (hp);}#endif#ifdef GETHOST_R_GLIBC_FLAVOR#ifdef HAVE_GETHOSTBYNAME_RintENTRY(gethostbyname_r)(const char *name, struct hostent *result,		       char *buffer, size_t buflen,		       struct hostent **rp, int *errp){	char namebuf[IDN_NAME_SIZE];	char *data;	size_t datalen;	idn_result_t r;	struct hostent he;	hostbuf_t buf;	int n;	if (idn_isprocessing)		return (REAL(gethostbyname_r)(name, result, buffer,					      buflen, rp, errp));	TRACE(("gethostbyname_r(name=%s,buflen=%d)\n",	       idn__debug_xstring(name, 60), buflen));	if (buflen <= sizeof(buf)) {		data = buf.data;		datalen = sizeof(buf);	} else {		data = malloc(buflen);		datalen = buflen;		if (data == NULL) {			*errp = NO_RECOVERY;			return (ENOMEM);		}	}	idn_isprocessing = 1;	idn_enable(1);	idn_nameinit(1);	r = idn_encodename(IDN_ENCODE_APP, name, namebuf, sizeof(namebuf));	if (r == idn_success)		name = namebuf;	*errp = 0;	n = REAL(gethostbyname_r)(name, &he, data, datalen, rp, errp);	if (n == 0 && *rp != NULL)		*rp = copy_decode_hostent_static(*rp, result, buffer, buflen,						 errp);	idn_isprocessing = 0;	if (data != buf.data)		free(data);	if (*errp != 0)		n = EINVAL;	/* XXX */	return (n);}#endif#ifdef HAVE_GETHOSTBYNAME2_RintENTRY(gethostbyname2_r)(const char *name, int af, struct hostent *result,			char *buffer, size_t buflen,			struct hostent **rp, int *errp){	char namebuf[IDN_NAME_SIZE];	char *data;	size_t datalen;	idn_result_t r;	struct hostent he;	hostbuf_t buf;	int n;	if (idn_isprocessing)		return (REAL(gethostbyname2_r)(name, af, result, buffer,					       buflen, rp, errp));	TRACE(("gethostbyname2_r(name=%s,buflen=%d)\n",	       idn__debug_xstring(name, 60), buflen));	if (buflen <= sizeof(buf)) {		data = buf.data;		datalen = sizeof(buf);	} else {		data = malloc(buflen);		datalen = buflen;		if (data == NULL) {			*errp = NO_RECOVERY;			return (ENOMEM);		}	}	idn_isprocessing = 1;	idn_enable(1);	idn_nameinit(1);	r = idn_encodename(IDN_ENCODE_APP, name, namebuf, sizeof(namebuf));	if (r == idn_success)		name = namebuf;	n = REAL(gethostbyname2_r)(name, af, &he, data, datalen, rp, errp);	if (n == 0 && *rp != NULL)		*rp = copy_decode_hostent_static(*rp, result, buffer, buflen,						 errp);	idn_isprocessing = 0;	if (data != buf.data)		free(data);	if (*errp != 0)		n = EINVAL;	/* XXX */	return (n);}#endif#ifdef HAVE_GETHOSTBYADDR_RintENTRY(gethostbyaddr_r)(GHBA_ADDR_T addr, GHBA_ADDRLEN_T len, int type,		       struct hostent *result,		       char *buffer, size_t buflen,		       struct hostent **rp, int *errp){	char *data;	size_t datalen;	struct hostent he;	hostbuf_t buf;	int n;	if (idn_isprocessing) {		return (REAL(gethostbyaddr_r)(addr, len, type, result,					      buffer, buflen, rp, errp));	}	TRACE(("gethostbyaddr_r(buflen=%d)\n", buflen));	if (buflen <= sizeof(buf)) {		data = buf.data;		datalen = sizeof(buf);	} else {		data = malloc(buflen);		datalen = buflen;		if (data == NULL) {			*errp = NO_RECOVERY;			return (ENOMEM);		}	}	idn_isprocessing = 1;	n = REAL(gethostbyaddr_r)(addr, len, type, &he,				   data, datalen, rp, errp);	if (n == 0 && *rp != NULL)		*rp = copy_decode_hostent_static(*rp, result, buffer, buflen,						 errp);	idn_isprocessing = 0;	if (data != buf.data)		free(data);	if (*errp != 0)		n = EINVAL;	/* XXX */	return (0);}#endif#else /* GETHOST_R_GLIBC_FLAVOR */#ifdef HAVE_GETHOSTBYNAME_Rstruct hostent *ENTRY(gethostbyname_r)(const char *name, struct hostent *result,		       char *buffer, int buflen, int *errp){	char namebuf[IDN_NAME_SIZE];	char *data;	size_t datalen;	idn_result_t r;	struct hostent *hp, he;	hostbuf_t buf;	if (idn_isprocessing)		return (REAL(gethostbyname_r)(name, result, buffer,					      buflen, errp));	TRACE(("gethostbyname_r(name=%s,buflen=%d)\n",	       idn__debug_xstring(name, 60), buflen));	if (buflen <= sizeof(buf)) {		data = buf.data;		datalen = sizeof(buf);	} else {		data = malloc(buflen);		datalen = buflen;		if (data == NULL) {			*errp = NO_RECOVERY;			return (NULL);		}	}	idn_isprocessing = 1;	idn_enable(1);	idn_nameinit(1);	r = idn_encodename(IDN_ENCODE_APP, name, namebuf, sizeof(namebuf));	if (r == idn_success)		name = namebuf;	hp = REAL(gethostbyname_r)(name, &he, data, datalen, errp);	if (hp != NULL)		hp = copy_decode_hostent_static(hp, result, buffer, buflen,						errp);	idn_isprocessing = 0;	if (data != buf.data)		free(data);	return (hp);}#endif#ifdef HAVE_GETHOSTBYADDR_Rstruct hostent *ENTRY(gethostbyaddr_r)(GHBA_ADDR_T addr, GHBA_ADDRLEN_T len, int type,		       struct hostent *result,		       char *buffer, int buflen, int *errp){	char *data;	size_t datalen;	struct hostent *hp, he;	hostbuf_t buf;	if (idn_isprocessing) {		return (REAL(gethostbyaddr_r)(addr, len, type, result,					      buffer, buflen, errp));	}	TRACE(("gethostbyaddr_r(buflen=%d)\n", buflen));	if (buflen <= sizeof(buf)) {		data = buf.data;		datalen = sizeof(buf);	} else {		data = malloc(buflen);		datalen = buflen;		if (data == NULL) {			*errp = NO_RECOVERY;			return (NULL);		}	}	idn_isprocessing = 1;	hp = REAL(gethostbyaddr_r)(addr, len, type, &he, data, datalen, errp);	if (hp != NULL)		hp = copy_decode_hostent_static(hp, result, buffer, buflen,						errp);	idn_isprocessing = 0;	if (data != buf.data)		free(data);	return (hp);}#endif#endif /* GETHOST_R_GLIBC_FLAVOR */#ifdef HAVE_GETIPNODEBYNAMEstruct hostent *ENTRY(getipnodebyname)(const char *name, int af, int flags, int *errp) {	char namebuf[IDN_NAME_SIZE];	idn_result_t r;	struct hostent *hp;	if (idn_isprocessing)		return (REAL(getipnodebyname)(name, af, flags, errp));	TRACE(("getipnodebyname(name=%s)\n", idn__debug_xstring(name, 60), af));	idn_isprocessing = 1;	idn_enable(1);	idn_nameinit(1);	r = idn_encodename(IDN_ENCODE_APP, name, namebuf, sizeof(namebuf));	if (r == idn_success)		name = namebuf;	hp = REAL(getipnodebyname)(name, af, flags, errp);	if (hp != NULL) {		struct hostent *newhp = copy_decode_hostent_dynamic(hp, errp);		if (newhp != hp) {			REAL(freehostent)(hp);			obj_lock(newhp);			hp = newhp;		}	}	idn_isprocessing = 0;	return (hp);}#endif#ifdef HAVE_GETIPNODEBYADDRstruct hostent *ENTRY(getipnodebyaddr)(const void *src, size_t len, int af, int *errp) {	struct hostent *hp;	if (idn_isprocessing)		return (REAL(getipnodebyaddr)(src, len, af, errp));	TRACE(("getipnodebyaddr()\n"));	idn_isprocessing = 1;	hp = REAL(getipnodebyaddr)(src, len, af, errp);	if (hp != NULL) {		struct hostent *newhp = copy_decode_hostent_dynamic(hp, errp);		if (newhp != hp) {			REAL(freehostent)(hp);			obj_lock(newhp);			hp = newhp;		}	}	idn_isprocessing = 0;	return (hp);}#endif#ifdef HAVE_FREEHOSTENTvoidENTRY(freehostent)(struct hostent *hp) {	TRACE(("freehostent(hp=%p)\n", (void *)hp));	if (obj_islocked(hp)) {		/*		 * We allocated the data.		 */		obj_unlock(hp);		free_copied_hostent(hp);	} else {		/*		 * It was allocated the original getipnodeby*().		 */		REAL(freehostent)(hp);	}}#endif#ifdef HAVE_GETADDRINFOintENTRY(getaddrinfo)(const char *nodename, const char *servname,		   const struct addrinfo *hints, struct addrinfo **res){	char namebuf[IDN_NAME_SIZE];	idn_result_t r;	struct addrinfo *aip;	int err;	if (nodename == NULL || idn_isprocessing)		return (REAL(getaddrinfo)(nodename, servname, hints, res));	TRACE(("getaddrinfo(nodename=%s)\n", idn__debug_xstring(nodename, 60)));	idn_isprocessing = 1;	idn_enable(1);	idn_nameinit(1);	r = idn_encodename(IDN_ENCODE_APP, nodename,			   namebuf, sizeof(namebuf));	if (r == idn_success)		nodename = namebuf;	err = REAL(getaddrinfo)(nodename, servname, hints, &aip);	if (err == 0 && aip != NULL) {		*res = copy_decode_addrinfo_dynamic(aip);		if (*res == NULL)			err = EAI_FAIL;		else 			obj_lock(*res);		if (aip != NULL)			REAL(freeaddrinfo)(aip);	}	idn_isprocessing = 0;	return (err);}#endif#ifdef HAVE_FREEADDRINFOvoidENTRY(freeaddrinfo)(struct addrinfo *aip) {	TRACE(("freeaddrinfo(aip=%p)\n", (void *)aip));	if (obj_islocked(aip)) {		/*		 * We allocated the data.		 */		obj_unlock(aip);		free_copied_addrinfo(aip);	} else {		/*		 * It was allocated the original getaddrinfo().		 */		REAL(freeaddrinfo)(aip);	}}#endif#ifdef HAVE_GETNAMEINFOintENTRY(getnameinfo)(const struct sockaddr *sa, GNI_SALEN_T salen,		   char *host, GNI_HOSTLEN_T hostlen, char *serv,		   GNI_SERVLEN_T servlen, GNI_FLAGS_T flags){	char name[IDN_NAME_SIZE];	size_t namelen = sizeof(name);	int code;	idn_result_t r;	if (host == NULL || hostlen == 0 || idn_isprocessing) {		return (REAL(getnameinfo)(sa, salen, host, hostlen,					  serv, servlen, flags));	}	TRACE(("getnameinfo(hostlen=%u)\n", hostlen));	idn_isprocessing = 1;	code = REAL(getnameinfo)(sa, salen, name, namelen,				 serv, servlen, flags);	if (code == 0 && name[0] != '\0') {		idn_enable(1);		idn_nameinit(1);		r = idn_decodename(IDN_DECODE_APP, name, host, hostlen);		switch (r) {		case idn_success:			code = 0;			break;		case idn_buffer_overflow:		case idn_nomemory:			code = EAI_MEMORY;			break;		default:			code = EAI_FAIL;			break;		}	}	idn_isprocessing = 0;	return (code);}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -