linux-socket寻址
环境
- ubuntu-14.04 
- glic-2.19 
- 工作目录: - /usr/include
数据结构
struct sockaddr
socketAPI接口,无关具体地址族,协议。
定义位置
x86_64-linux-gnu/sys/socket.h => x86_64-linux-gnu/bits/socket.h
| 1 | /* Structure describing a generic socket address. */ | 
Note:
- =>表示包含
strcut sockaddr_in
具体类型数据结构,用来操作地址族,IP,端口。
定义位置
netinet/in.h
| 1 | /* Structure describing an Internet socket address. */ | 
struct in_addr
定义IP
定义位置
netinet/in.h
| 1 | /* Internet address. */ | 
关系
in_addr => sockaddr_in => sockaddr
Note:
- =>表示构成
说明
socket地址结构传递方向
- 从进程到内核 - 需要传入参数(套接字地址大小,告诉内核需要复制多少字节) - bind
- connect
- sendto
- sendmsg
 
- 从内核到进程 - 需要传入传出参数(套接字地址大小,告诉内核需要复制多少字节,以及反馈进程,返回的地址结构大小) - accept
- recvfrom
- recvmsg
- getpeername
- getsockname