Loading

Linux socket编程中调用 inet_ntoa 函数产生的段错误 “Segmentation fault (core dumped)” 的原因及解决办法

调用 inet_ntoa 函数产生的段错误 “Segmentation fault (core dumped)” 的原因及解决办法

struct sockaddr_in   client_addr;
...
printf("connection from %s\n", inet_ntoa(client_addr.sin_addr));

执行到 inet_ntoa 时会产生段错误:
Segmentation fault (core dumped)

【原因】
据说是在64位环境下会产生错误,而在32位系统下运行正常。

【解决办法】
加入头文件:
#include <arpa/inet.h>

编译后执行正常。

 

来源:https://blog.csdn.net/iw1210/article/details/11798245

posted @ 2020-05-12 18:45  拾月凄辰  阅读(461)  评论(0编辑  收藏  举报