当前位置: 技术问答>linux和unix
error: ‘struct in_addr’ has no member named ‘S_un’
来源: 互联网 发布时间:2016-12-17
本文导语: 用GCC调试出了 error: ‘struct in_addr’ has no member named ‘S_un’ 。找了MSDN,谷歌,一堆英文试着看了几下,也没找着我把代码列出,各位帮我看下哪里错了,在这先谢谢了 #include #include #include #include #include ...
用GCC调试出了 error: ‘struct in_addr’ has no member named ‘S_un’ 。找了MSDN,谷歌,一堆英文试着看了几下,也没找着我把代码列出,各位帮我看下哪里错了,在这先谢谢了
#include
#include
#include
#include
#include
#include
#include
int main(int argc,char *argv[])
{
int server_socket;
int client_socket;
char buffer[512];
pid_t child_id;
int read_count;
int addr_len = sizeof(struct sockaddr_in);
struct sockaddr_in ser_addr,client_addr;
memset(buffer,0,512);
server_socket = socket(AF_INET,SOCK_STREAM,0);
if(server_socket 0)
{
close(client_socket);
}
}
return 0;
}
#include
#include
#include
#include
#include
#include
#include
int main(int argc,char *argv[])
{
int server_socket;
int client_socket;
char buffer[512];
pid_t child_id;
int read_count;
int addr_len = sizeof(struct sockaddr_in);
struct sockaddr_in ser_addr,client_addr;
memset(buffer,0,512);
server_socket = socket(AF_INET,SOCK_STREAM,0);
if(server_socket 0)
{
close(client_socket);
}
}
return 0;
}
|
ser_addr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
这是从哪儿摘录的
unix系统中通常没有大写的命令或函数或成员
试试
ser_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
这是从哪儿摘录的
unix系统中通常没有大写的命令或函数或成员
试试
ser_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
|
/* Internet address. */
struct in_addr {
__be32 s_addr;
};
上面是内核里的定义。
估计楼主copy代码的时候有问题,呵呵。
struct in_addr {
__be32 s_addr;
};
上面是内核里的定义。
估计楼主copy代码的时候有问题,呵呵。
|
改成下面的试试看
ser_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
|
楼主没copy错,你的程序应该是在windows上运行吧,
你是Linux中,还是windows?
winsock.h中有如下定义:
你是Linux中,还是windows?
winsock.h中有如下定义:
struct in_addr {
union {
struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
struct { u_short s_w1,s_w2; } S_un_w;
u_long S_addr;
} S_un;
#define s_addr S_un.S_addr
#define s_host S_un.S_un_b.s_b2
#define s_net S_un.S_un_b.s_b1
#define s_imp S_un.S_un_w.s_w2
#define s_impno S_un.S_un_b.s_b4
#define s_lh S_un.S_un_b.s_b3
};
|
错误报警很明白啊!就是说没有S_un这个成员啊!