Prayer

在一般中寻求卓越
posts - 1256, comments - 190, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

sockaddr_in 结构体在什么头文件中声明

Posted on 2008-12-31 10:51 Prayer 阅读(50136) 评论(6)  编辑 收藏 引用 所属分类: SOCKET
在编写Linux下的网络程序时,使用了sockaddr_in结构,在头文件中声明了<sys/socket.h>,系统仍不承认sockaddr_in结构,这是为什么? 

#include <netinet/in.h>   

#include <sys/param.h>. p  D+ r! g$ [0 k! F  G5 B; }* m
#include <sys/stat.h>: x7 q# y& F! X2 L0 d
#include <sys/ioctl.h>; ^1 I; }% o" B( {8 ~) c6 H* p) \
#include <sys/socket.h>5 h0 V  H& v2 W+ k3 I
#include <sys/time.h>2 Y4 a8 U) j4 ^2 _8 t7 T1 U
#include <sys/file.h>
% G9 t9 c9 C5 T1 v$ @: u. l
& m3 p  H' Z, \6 t% p  s, ]#include <netinet/in.h>( p  _0 F, P$ H9 \; A. d
#include <netinet/ip.h>0 \- F& z( \+ ]! i
#include <arpa/ftp.h>
3 r( b/ n/ w' j+ P' W; P1 w#include <arpa/inet.h>* a( }. Y+ R' @+ u, I
#include <arpa/telnet.h>
$ n! b$ l9 a9 J: S5 [9 m9 I& i* A2 N1 V7 ]
#include <stdio.h>
  F8 d! W1 Z6 k  c3 H3 o, K) O#include <signal.h>4 U" E. v! B) k+ |
#include <string.h>
' g1 \5 A! @& E#include <stdlib.h>
# e/ c" I& p+ v4 D1 g#include <unistd.h>% |4 H# c  x& h6 a" x
#include <errno.h>! @! U0 H- I" h& b0 K1 w
#include <netdb.h>

Feedback

# re: sockaddr_in 结构体在什么头文件中声明  回复  更多评论   

2009-11-01 15:02 by Pylipala
是在下面这个文件吧:
#include <netinet/in.h>
你已经包含了这个文件了。编译器找不到大概是因为你写的是C文件,但是用的C++的语法。在 sockaddr_in 前面加上 struct 试试。

# re: sockaddr_in 结构体在什么头文件中声明  回复  更多评论   

2011-10-16 12:37 by ring
我也遇到了这个问题,很是郁闷,楼主如何解决的,能不能留个联系地址,我的邮箱454387468@qq.com望不吝赐教

# re: sockaddr_in 结构体在什么头文件中声明  回复  更多评论   

2011-10-23 10:56 by 高强
@ring
加上 #include <netinet/in.h>就好了

# re: sockaddr_in 结构体在什么头文件中声明  回复  更多评论   

2012-11-24 17:46 by heimu
#include <sys/un.h>

# re: sockaddr_in 结构体在什么头文件中声明  回复  更多评论   

2013-01-13 21:01 by 皮卡
一楼正解

# re: sockaddr_in 结构体在什么头文件中声明  回复  更多评论   

2016-06-02 15:13 by 游客游过
一楼正解

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理