'inet_ntoa' 未声明错误
'inet_ntoa' not declared error
我正在尝试使用 inet_ntoa 函数
写入以下代码:
printf("Got connection from: %s:%d\n", inet_ntoa(cli_addr.sin_addr.s_addr), cli_addr.sin_port);
使用以下内容包括:
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
但是,使用 g++/gcc 我总是得到错误:
error: ‘inet_ntoa’ was not declared in this scope
如果我评论那一行,代码就很好。
运行 Ubuntu12.04.
谁能告诉我我错过了什么?
谢谢!
从 man inet_ntoa
开始,您似乎必须在包含 headers:
之前定义 _BSD_SOURCE
#define _BSD_SOURCE
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
我正在尝试使用 inet_ntoa 函数 写入以下代码:
printf("Got connection from: %s:%d\n", inet_ntoa(cli_addr.sin_addr.s_addr), cli_addr.sin_port);
使用以下内容包括:
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
但是,使用 g++/gcc 我总是得到错误:
error: ‘inet_ntoa’ was not declared in this scope
如果我评论那一行,代码就很好。
运行 Ubuntu12.04.
谁能告诉我我错过了什么?
谢谢!
从 man inet_ntoa
开始,您似乎必须在包含 headers:
_BSD_SOURCE
#define _BSD_SOURCE
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>