linux网络编程之地址结构sockaddr和sockaddr_in的区别
【摘要】 1、介绍sockaddr
结构体struct sockaddr在/usr/include/linux/socket.h中定义
struct sockaddr { unsigned short sa_family; // 2 bytes address family, AF_xxx char sa_data[14]; // 14 bytes of proto...
1、介绍sockaddr
结构体struct sockaddr在/usr/include/linux/socket.h中定义
-
struct sockaddr {
-
unsigned short sa_family; // 2 bytes address family, AF_xxx
-
char sa_data[14]; // 14 bytes of protocol address
-
};
2、介绍sockaddr_in
结构体struct sockaddr_in在/usr/include/netinet/in.h中定义,是IPv4的地址结构
-
struct sockaddr_in {
-
short sin_family; // 2 bytes e.g. AF_INET, AF_INET6
-
unsigned short sin_port; // 2 bytes e.g. htons(3490)
-
struct in_addr sin_addr; // 4 bytes see struct in_addr, below
-
char sin_zero[8]; // 8 bytes zero this if you want to
-
};
-
-
struct in_addr {
-
unsigned long s_addr; // 4 bytes load with inet_pton()
-
};
3、对比总结
struct sockaddr是通用的套接字地址,而struct sock
文章来源: chenyu.blog.csdn.net,作者:chen.yu,版权归原作者所有,如需转载,请联系作者。
原文链接:chenyu.blog.csdn.net/article/details/56481754
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)