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

📄 host_serv.c

📁 unix网络编程卷1:套接口API的全书源码
💻 C
字号:
/* include host_serv */#include	"unp.h"struct addrinfo *host_serv(const char *host, const char *serv, int family, int socktype){	int				n;	struct addrinfo	hints, *res;	bzero(&hints, sizeof(struct addrinfo));	hints.ai_flags = AI_CANONNAME;	/* always return canonical name */	hints.ai_family = family;		/* AF_UNSPEC, AF_INET, AF_INET6, etc. */	hints.ai_socktype = socktype;	/* 0, SOCK_STREAM, SOCK_DGRAM, etc. */	if ( (n = getaddrinfo(host, serv, &hints, &res)) != 0)		return(NULL);	return(res);	/* return pointer to first on linked list */}/* end host_serv *//* * There is no easy way to pass back the integer return code from * getaddrinfo() in the function above, short of adding another argument * that is a pointer, so the easiest way to provide the wrapper function * is just to duplicate the simple function as we do here. */struct addrinfo *Host_serv(const char *host, const char *serv, int family, int socktype){	int				n;	struct addrinfo	hints, *res;	bzero(&hints, sizeof(struct addrinfo));	hints.ai_flags = AI_CANONNAME;	/* always return canonical name */	hints.ai_family = family;		/* 0, AF_INET, AF_INET6, etc. */	hints.ai_socktype = socktype;	/* 0, SOCK_STREAM, SOCK_DGRAM, etc. */	if ( (n = getaddrinfo(host, serv, &hints, &res)) != 0)		err_quit("host_serv error for %s, %s: %s",				 (host == NULL) ? "(no hostname)" : host,				 (serv == NULL) ? "(no service name)" : serv,				 gai_strerror(n));	return(res);	/* return pointer to first on linked list */}

⌨️ 快捷键说明

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