ga_unixstruct.c

来自「unix 网络编程第三版源代码 unix 网络编程第三版源代码」· C语言 代码 · 共 37 行

C
37
字号
#include	"gai_hdr.h"#ifdef	UNIXDOMAINintga_unixstruct(const char *path, struct addrinfo *hintsp,			  struct addrinfo **result, int socktype){	struct addrinfo		*ai;	struct sockaddr_un	*unp;	if ( (ai = calloc(1, sizeof(struct addrinfo))) == NULL)		return(EAI_MEMORY);	ai->ai_flags = 0;	ai->ai_family = AF_LOCAL;	ai->ai_socktype = socktype;	ai->ai_protocol = 0;		/* allocate and fill in a socket address structure */	ai->ai_addrlen = sizeof(struct sockaddr_un);	if ( (ai->ai_addr = malloc(ai->ai_addrlen)) == NULL)		return(EAI_MEMORY);	unp = (struct sockaddr_un *) ai->ai_addr;	unp->sun_family = AF_UNIX;	strncpy(unp->sun_path, path, sizeof(unp->sun_path));	ai->ai_canonname = NULL;	ai->ai_next = NULL;	*result = ai;	if (hintsp->ai_flags & AI_PASSIVE)		unlink(path);		/* OK if this fails */	return(0);		/* success */}#endif	/* UNIXDOMAIN */

⌨️ 快捷键说明

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