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

📄 test_inet_pton.c

📁 unix网络编程卷1:套接口API的全书源码
💻 C
字号:
#include	"../lib/unp.h"#ifndef	AF_INET6#define	AF_INET6	AF_MAX+1	/* just to let this compile */#endifint		inet_pton(int, const char *, void *);intmain(int argc, char **argv){	int		i;	char	buff[100];	/*	 * Make certain that we can test the difference between 0.0.0.0	 * being acceptable for AF_INET (but not acceptable for AF_INET6)	 * and 0::0 being OK for AF_INET6 (but not OK for AF_INET).	 * This way a server can be coded as protocol independent (IPv4 or	 * IPv6) but let the user specify the local IP address as either	 * 0.0.0.0 or 0::0 as an indirect way of telling the server when	 * it starts, which protocol to use (but still allowing the server	 * to bind the wildcard address).	 */	if ( (i = inet_pton(AF_INET, "0.0.0.0", buff)) != 1)	/* should be OK */		printf("AF_INET, 0.0.0.0 returned: %d\n", i);	if ( (i = inet_pton(AF_INET6, "0.0.0.0", buff)) != 0)		printf("AF_INET6, 0.0.0.0 returned: %d\n", i);	if ( (i = inet_pton(AF_INET6, "0::0", buff)) != 1)		/* should be OK */		printf("AF_INET6, 0::0 returned: %d\n", i);	if ( (i = inet_pton(AF_INET, "0::0", buff)) != 0)		printf("AF_INET, 0::0 returned: %d\n", i);	printf("inet_pton(AF_INET6, \"1.2.3.4\", buff) returns %d\n",		    inet_pton(AF_INET6,  "1.2.3.4", buff));	printf("inet_pton(AF_INET6, \"::1.2.3.4\", buff) returns %d\n",		    inet_pton(AF_INET6,  "::1.2.3.4", buff));	exit(0);}

⌨️ 快捷键说明

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