TCP/IP——网络编程模型
小狼@http://blog.csdn.net/xiaolangyangyang
1 socket结构体
struct sockaddr {
unsigned short sa_family; /* address族, AF_xxx */
char sa_data[14]; /* 14 bytes的协议地址 */
};
struct sockaddr_in
{
short int sin_family; /* Internet地址族 */
unsigned short int sin_port; /* 端口号 */
struct in_addr sin_addr; /* Internet地址 */
unsigned char sin_zero[8]; /* 添0(和struct sockaddr1样大小)*/
};
struct in_addr {
unsigned long s_addr;
};
2 socket经常使用函数
int socket(int domain, int type, int protocol);
int bind(int sockfd, struct sockaddr *my_addr, int addrlen);
int connect(int sockfd, struct sockaddr *serv_addr, int addrlen);
int listen(int sockfd, int backlog);
int accept(int sockfd, void *addr, int *addrlen);
int send(int sockfd, const void *msg, int len, int flags);
int recv(int sockfd, void *buf, int len, unsigned int flags);
int sendto(int sockfd, const void *msg, int len, unsigned int flags, const struct sockaddr *to, int tolen);
int recvfrom(int sockfd, void *buf, int len, unsigned int flags, struct sockaddr *from, int *fromlen);
close(sockfd);
int shutdown(int sockfd, int how);
int setsockopt(int sockfd, int level, int name, char *value, int *optlen);
int getsockopt(int sockfd, int level, int name, char *value, int *optlen);
int getpeername(int sockfd, struct sockaddr *addr, int *addrlen);
retcode = getsockname(socket, name, namelen);
struct hostent *gethostbyname(const char *name);
retcode = gethostbyaddr(addr, len, type);
retcode = getprotobyname(name);
int fcntl(int fd, int cmd, long arg);
3 低级网络编程模型(阻塞I/O模型)
4 Linux下网络编程5种I/O模型
上一篇 Spark安装