cname_to_comp.c

来自「聊天程序~使用LINUX c 语言实现~」· C语言 代码 · 共 38 行

C
38
字号
/* cname_to_comp.c */#include <cnaiapi.h>computer cname_to_comp(char *cname) {	computer		c;	struct hostent		*hp;	cnaiapi_init();#if defined(FreeBSD) || defined(LINUX)	pthread_mutex_lock(&cname_mutex);#endif	hp = gethostbyname(cname);	if (hp == NULL) {#if defined(FreeBSD) || defined(LINUX)		pthread_mutex_unlock(&cname_mutex);#endif		return -1;	}		if (hp->h_addrtype != AF_INET ||	    hp->h_length != sizeof(computer)) {#if defined(FreeBSD) || defined(LINUX)		pthread_mutex_unlock(&cname_mutex);#endif		return -1;	}	  	c = *((long *) hp->h_addr);#if defined(LINUX) || defined(SOLARIS)	pthread_mutex_unlock(&cname_mutex);#endif	return c;}

⌨️ 快捷键说明

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