int accept(int socket, struct sockaddr *address, socklen_t *address_len);
int bind(int socket, const struct sockaddr *address, socklen_t address_len);
int connect(int socket, const struct sockaddr *address, socklen_t address_len);
int getpeername(int socket, struct sockaddr *address, socklen_t *address_len);
int getsockname(int socket, struct sockaddr *address, socklen_t *address_len);
int getsockopt(int socket, int level, int option_name, void *option_value, socklen_t *option_len);
int listen(int socket, int backlog);
ssize_t recv(int socket, void *buffer, size_t length, int flags);
ssize_t recvfrom(int socket, void *buffer, size_t length, int flags, struct sockaddr *address, socklen_t *address_len);
ssize_t recvmsg(int socket, struct msghdr *message, int flags);
ssize_t send(int socket, const void *message, size_t length, int flags);
ssize_t sendmsg(int socket, const struct msghdr *message, int flags);
ssize_t sendto(int socket, const void *message, size_t length, int flags, const struct sockaddr *dest_addr, socklen_t dest_len);
int setsockopt(int socket, int level, int option_name, const void *option_value, socklen_t option_len);int shutdown(int socket, int how);
int socket(int domain, int type, int protocol);
int socketpair(int domain, int type, int protocol, int socket_vector[2]);
在那个《深入理解计算机系统》11章有专门说的这个网络编程
client 流程:
socket
connect
send
receive
send EOF
close
server流程:
socket
bind
listen
accept
receive
send
receive
close
=============================================================
其他比较细的地方有
struct sockaddr (socket.h)
sa_family_t sa_family address family
char sa_data[] socket address (variable-length data)
struct sockaddr_in (netinet/in.h)
short int sin_family; /* Address family */ unsigned short int sin_port; /* Port number */ struct in_addr sin_addr; /* Internet address */ unsigned char sin_zero[8]; /* Same size as struct sockaddr */
======================================================附一些头文件:#include <arpa/inet.h>uint32_t htonl(uint32_t);uint16_t htons(uint16_t);uint32_t ntohl(uint32_t);uint16_t ntohs(uint16_t);
--
in_addr_t inet_addr(const char *);char *inet_ntoa(struct in_addr);const char *inet_ntop(int, const void *restrict, char *restrict, socklen_t);int inet_pton(int, const char *restrict, void *restrict);===#include <netinet/in.h>The <netinet/in.h> header shall define the sockaddr_in structure that includes at least the following members:
sa_family_t sin_family AF_INET.in_port_t sin_port Port number.struct in_addr sin_addr IP address.=================附上两篇非常棒的文章:http://www.ibm.com/developerworks/cn/education/linux/l-sock/section4.html#ibm-pconhttp://www.ibm.com/developerworks/cn/education/linux/l-sock2/index.html