调用 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

相关文章:

  • 2021-04-07
猜你喜欢
  • 2021-09-11
  • 2021-04-25
  • 2021-05-28
  • 2021-12-16
  • 2022-01-13
  • 2022-12-23
  • 2022-01-30
相关资源
相似解决方案