3int sal_getpeername (int socket, struct sockaddr *name, socklen_t *namelen);
4int sal_getsockname (int socket, struct sockaddr *name, socklen_t *namelen);
5int sal_getsockopt (int socket, int level, int optname, void *optval, socklen_t *optlen);
6int sal_setsockopt (int socket, int level, int optname, const void *optval, socklen_t optlen);
7int sal_listen(int socket, int backlog);
8int sal_recvfrom(int socket, void *mem, size_t len, int flags,
9 struct sockaddr *from, socklen_t *fromlen);
10int sal_sendto(int socket, const void *dataptr, size_t size, int flags,
11 const struct sockaddr *to, socklen_t tolen);
12int sal_socket(int domain, int type, int protocol);
13int sal_closesocket(int socket);
14int sal_ioctlsocket(int socket, long cmd, void *arg);
2.5 BSD Socket API 介绍
创建套接字(socket)
1int socket(int domain, int type, int protocol);
创建一个BSD套接字
分配一个fd文件描述符
通过sal_socket()接口创建套接字
初始化fd文件描述符,然后将套接字socket放入dfs_fd
绑定套接字(bind)
1int bind(int s, const struct sockaddr *name, socklen_t namelen);
调用sal_bind()
建立连接(connect)
1int connect(int s, const struct sockaddr *name, socklen_t namelen)sal_connect
调用sal_connect()
监听套接字(listen)
1int listen(int s, int backlog)
接收连接(accept)
1int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
TCP 数据发送(send)
1int send(int s, const void *dataptr, size_t size, int flags)
TCP 数据接收(recv)
1int recv(int s, void *mem, size_t len, int flags)
UDP 数据发送(sendto)
1int sendto(int s, const void *dataptr, size_t size, int flags, const struct sockaddr *to, socklen_t tolen)
UDP 数据接收(recvfrom)
1int recvfrom(int s, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen)
关闭套接字(closesocket)
1int closesocket(int s)
按设置关闭套接字(shutdown)
1int shutdown(int s, int how)
设置套接字选项(setsockopt)
1int setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen)
获取套接字选项(getsockopt)
1int getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
获取远端地址信息(getpeername)
1int getpeername(int s, struct sockaddr *name, socklen_t *namelen)
获取本地地址信息(getsockname)
1int getsockname(int s, struct sockaddr *name, socklen_t *namelen)
配置套接字参数(ioctlsocket)