Linux 网络编程 套接字结构
来源:互联网 发布:wpf 管理系统源码购 编辑:程序博客网 时间:2024/06/05 06:19
IPV4 套接子结构
struct sockaddr_in{
uint8_t sin_len; //套接字长度,后来加入的参数,为了支持兼容和确定长度
sa_family_t sin_family; //协议类型
in_port_t sin_port; //端口号 16位
struct in_addr sin_addr; //地址 32位
char sin_zero[8]; //未使用
};
struct in_addr {
in_addr_t s_addr; //32位地址
};
POSIX 规范只需要这个结构中的三个,family ,addr ,port, 对与这个规范来说,这个大小是可以接受的,现在很多网际协议套接字大小至少都有16字节.
但是后来一个通用的结构出现了:
struct sockaddr {
uint8_t sa_len;
sa_family_t sa_family ;
char sa_data[14];
};
所以后来的bind 需要强制转换参数类型,仅仅因为如此罢了。
ipv6 的 结构:
struct in6_addr {
unit8_t s6_addr[16];
};
struct sockaddr_in6 {
uint8_t sin6_len;
sa_family_t sin6_family;
in_port_t sin6_port;
uint32_t sin6_addr;
uint32_t sin6_scope_id;
};
套接字的传递:
从进程到内核传递套接字地址结构的函数有3个,bind ,connect,sendto.
从内核到进程传递套接字地址结构的函数一共有4个,accept,recvfrom,getsockname,getpeername.
查看原文:http://zmrlinux.com/2016/03/05/linux-%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b-%e5%a5%97%e6%8e%a5%e5%ad%97%e7%bb%93%e6%9e%84/
- Linux网络编程---套接字结构
- Linux 网络编程 套接字结构
- Linux网络编程 套接字
- Linux网络编程 套接字
- Linux套接字网络编程
- 六、Linux网络编程-socket、套接字地址结构、地址转换、字节序、套接字类型
- Linux网络编程--套接字编程
- 【Linux网络编程】原始套接字编程
- Linux网络编程 UDP套接字编程
- linux网络编程----套接字编程
- linux网络编程之套接字编程
- Linux网络编程:8. 套接字选项
- Linux网络编程:10. 原始套接字
- Linux网络编程:原始套接字
- Linux网络编程: 原始套接字
- LINUX网络编程之套接字
- Linux网络编程--8. 套接字选项
- Linux网络编程: 原始套接字
- GET和POST的区别
- angularjs前端框架
- Python图像处理库PIL的ImageSequence模块介绍
- 首篇
- 7.数据对象映射模式
- Linux 网络编程 套接字结构
- CodeForces - 151A Soft Drinking (数学水题)
- 从输入URL到页面加载完成的过程中都发生了什么事情?
- 问题 K: 序列的区间操作
- linux下查看和添加PATH环境变量
- web.xml中在Servlet中获取context-param和init-param内的参数
- 几种基本排序的java实现
- hdu 5635 LCP Array
- Xcode中的文件结构