/** * ---结构体--- * * #include <sys/socket.h> * struct sockaddr { * unsigned short sa_family; * char sa_data[14]; * } * * #include <netinet/in.h> * struct sockaddr_in { * short int sin_family; //sa_family_t * unsigned short sin_port; //in_port_t * struct in_addr sin_addr; * unsigned char sin_zero[8]; * } * * #include <netinet/in.h> * sturct in_addr { * uint32_t s_addr; * } */ /** * --IP转换--- * ulong inet_addr(const char *ip); //将一个点分十进制的ip转换成一个网络字节序的长整型数 * int inet_aton(const char *ip, struct in_addr *inp); //将一个字符串ip转换成一个32位的网络字节序 * char *inet_ntoa(sturct in_addr in); */ /** * ---域名转换--- * #include <netdb.h> * struct hostent{ * char *h_name; * char **h_aliases; * short h_addrtype; * short h_length; * char **h_addr_list; * } * #define h_addr h_addr_list[0] * sturct hostent *h = gethostbyname(const char *hostname); //结果会存在resbuf里边 * */ /** * ---字节序转换--- * #include <arpa/inet.h> * uint32_t htonl(uint32_t hostlong) * uint32_t ntohl(uint32_t hostlong) * uint16_t htons(unit16_t hostshort) * uint16_t ntohs(uint16_t hostshort) */ /** * */ /** * int socket(int domain, int type, int protocol); * int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen); * int listen(int sockfd, int backlog); * int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen); * int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen); * int send(int sockfd, const void *buf, size_t len, int flags); * int recv(int sockfd, void *buf, size_t len, int flags); */