`socklen_t' has not been declared

羽飞 2012-09-13 08:52:04
我在SunOS上编译一个东西,出现下面的错误:

In file included from /data03/OBGRP/ob60/ob_rel/include/public/common/base/base_func.h:23,
from /data03/OBGRP/ob60/ob_rel/include/public/common/sdlbuffer/sdl_basic_objs.h:19,
from /data01/JFGRP/wangyl11/work/openbilling60/mediation/codec/sdl/codec_sdl_c.h:16,
from ../src/realtime.h:5,
from ../src/socket_for_tcpserver.cpp:10:
/usr/include/arpa/inet.h:69: error: `socklen_t' has not been declared
/usr/include/arpa/inet.h:72: error: `in_addr_t' does not name a type
/usr/include/arpa/inet.h:74: error: `in_addr_t' does not name a type
/usr/include/arpa/inet.h:75: error: variable `in_addr inet_makeaddr' has initializer but incomplete type
/usr/include/arpa/inet.h:75: error: `in_addr_t' was not declared in this scope
/usr/include/arpa/inet.h:75: error: `in_addr_t' was not declared in this scope
/usr/include/arpa/inet.h:76: error: `in_addr_t' does not name a type
/usr/include/arpa/inet.h:77: error: `in_addr_t' does not name a type
/usr/include/arpa/inet.h:75: error: storage size of `inet_makeaddr' isn't known

上面的说未定义的都可以在/usr/include/netinet/in.h中找到,其中socklen_t在两个文件中定义过:netinet/in.h和sys/socket.h;
在netinet/in.h中有如下的描述:
/*
* The socklen definitions are reproduced here from sys/socket.h so as to
* not introduce that namespace into existing users of netinet/in.h.
*/

在sys/socket.h中有如下的描述:
/*
* The socklen definitions are reproduced in netinet/in.h for the inet6_
* functions. Exposing all of sys/socket.h via netinet/in.h breaks existing
* applications and is not required by austin.
*/

在这个文件 /usr/include/arpa/inet.h 中:
#if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
#include <sys/socket.h>
#endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */

#include <netinet/in.h>
#if defined(_XPG4_2) && !defined(__EXTENSIONS__)
#include <sys/byteorder.h>
#endif /* defined(_XPG4_2) && !defined(__EXTENSIONS__) */

...全文
790 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
mymtom 2012-09-17
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 的回复:]
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

我一般就man inetaddr,粘贴上那些头文件够用。
[/Quote]
++
我也是用这个man inet_addr哎,只不过FreeBSD上多一个#include <sys/types.h>, 如果要解析主机名加上
#include <netdb.h>

写的多了,顺手就出来了!

qq120848369 2012-09-14
  • 打赏
  • 举报
回复
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

我一般就man inetaddr,粘贴上那些头文件够用。
mymtom 2012-09-14
  • 打赏
  • 举报
回复
Unix下的TCP/IP网络编程包含以下的5个文件,在绝大多数系统都不会有问题,

#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netdb.h>

mymtom 2012-09-14
  • 打赏
  • 举报
回复
你就不能试试吗。

先看看标准怎么说的吧!

The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group
NAME

sys/socket.h - Internet Protocol family

SYNOPSIS



#include <sys/socket.h>

DESCRIPTION

<sys/socket.h> makes available a type, [B]socklen_t[/B], which is an unsigned opaque integral type of length of at least 32 bits. To forestall portability problems, it is recommended that applications should not use values larger than 232 - 1.
羽飞 2012-09-14
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
#include <sys/socket.h>
[/Quote]
/usr/include/arpa/inet.h
这个头文件已经包含了 netinet/in.h
而且某个条件下会包含 sys/socket.h
羽飞 2012-09-14
  • 打赏
  • 举报
回复
昨天调整了一下头文件引用的顺序,通过了
今天又变回原样,一样通过,很奇怪
mymtom 2012-09-14
  • 打赏
  • 举报
回复

#include <sys/socket.h>
morris88 2012-09-14
  • 打赏
  • 举报
回复
哎,我也看不出问题所在
羽飞 2012-09-14
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]

你就不能试试吗。

先看看标准怎么说的吧!

The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group
NAME

sys/socket.h - Internet Protocol family

SYNOPSIS



#include <sys/socke……
[/Quote]
何必动怒
说的这些也都试过了,
sys/socket.h和netinet/in.h都有的
但是现在又无法重现了,想找到问题的原因,把代码恢复到原样都不重现,很郁闷
努力重现中.....
羽飞 2012-09-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

需要指明 defined(__xx__) 类的东西么?
[/Quote]

我有好几个地方引用这个东西,但是只有一个文件报错
morris88 2012-09-13
  • 打赏
  • 举报
回复
需要指明 defined(__xx__) 类的东西么?

23,121

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧