Chinaunix
标题:
inet_ntoa,inet_ntop 函数疑问
[打印本页]
作者:
philarlala
时间:
2016-08-01 11:37
标题:
inet_ntoa,inet_ntop 函数疑问
通过accept 获取到cliaddr,然后打印
printf("Welcome %s here!\n", inet_ntoa(cliaddr.sin_addr));
printf("Welcome %s here!\n", inet_ntop(AF_INET,&cliaddr.sin_addr,buf,sizeof(buf));
通过以上两种方式打印都会出现segment fault 错误
如果先inet_ntop(AF_INET,&cliaddr.sin_addr,buf,sizeof(buf),然后打印buf ,ip地址就不是client 的ip
printf("Welcome %s here!\n", buf);
通过网上查资料说,在64位的机器下,需要<arpa/inet.h> 头文件,添加头文件,编译运行正确。
疑问:
1.inet_ntoa,inet_ntop ,都是在arpa/inet.h 头文件下的,为什么没有使用这个头文件,编译不报错
2.尝试过判断inet_ntop,inet_ntoa的返回值,是否为NULL,编译的时候有warning 提示comparison between pointer and integer,
为什么inet_ntop,inet_ntoa的返回值是int的?跟man 出来的结果不一样的,难道是有其他地方有定义?
加上<arpa/inet.h>头文件就没有warning 了
作者:
hellioncu
时间:
2016-08-01 11:44
没申明,缺少返回值是int
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2