创建

socket

  1. int socket(int domain, int type, int protocol);

命名/绑定

bind

  1. int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);

监听

listen

  1. int listen(int sockfd, int backlog);

发送连接(主动)

connect

  1. int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);

接收连接(被动)

accept

  1. int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);

读写数据

send/recv

  1. ssize_t send(int sockfd, const void *buf, size_t len, int flags);
  1. ssize_t recv(int sockfd, void *buf, size_t len, int flags);

sendto/recvfrom

  1. ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);
  1. ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen);

sendmsg/recvmsg

  1. ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags);
  1. ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags);

write/read

  1. ssize_t write(int fd, const void *buf, size_t count);
  1. ssize_t read(int fd, void *buf, size_t count);

关闭连接(主动)

close

  1. int close(int fd);

shutdown

  1. int shutdown(int sockfd, int how);