Ron*_*Ron 5 c c++ linux ubuntu-12.04
我尝试使用 inet_ntoa 函数写入以下代码:
\n\nprintf("Got connection from: %s:%d\\n", inet_ntoa(cli_addr.sin_addr.s_addr), cli_addr.sin_port);\nRun Code Online (Sandbox Code Playgroud)\n\n使用以下内容包括:
\n\n#include <sys/socket.h>\n#include <netinet/in.h>\n#include <arpa/inet.h>\nRun Code Online (Sandbox Code Playgroud)\n\n但是,使用 g++/gcc 我总是收到错误:
\n\n\n\n\n错误:\xe2\x80\x98inet_ntoa\xe2\x80\x99 未在此范围内声明
\n
如果我评论该行,则代码就很好。
\n\n运行在Ubuntu12.04下。
\n\n谁能告诉我我错过了什么?
\n\n谢谢!
\n从man inet_ntoa看来你必须_BSD_SOURCE在包含标题之前定义:
#define _BSD_SOURCE
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6904 次 |
| 最近记录: |