数据结构:
socket通用定义
struct sockaddr {
u_char sa_len;
u_short sa_family;
char sa_data[14];//14B
}
socket PF_INET协议族定义
struct sockaddr_in
{
u_char sin_len;
u_short sin_family;
u_short sin_port;//2B
struct in_addr sin_addr;//4B
char sin_zero[8];//8B
}
struct in_addr {
u_long s_addr;
};
struct hostent {
char *h_name;
char **h_aliases;
int h_addrtype;
int h_length;
char **h_addr_list;
};
公共函数
int Socket( int domain, int type, int protocol)
int bind(int sockfd,struct sockaddr * my_addr,int addrlen)
int connect(int sockfd,struct sockaddr *server_addr,int sockaddr_len)
close(int sockfd);
uint32_t htonl(uint32_t hostlong);
uint16_t htons(uint16_t hostshort);
uint32_t ntohl(uint32_t netlong);
uint16_t ntohs(uint16_t netshort);
int inet_aton(const char *string, struct in_addr*addr);
in_addr inet_addr(const char *cp)
in_addr inet_network(const char *cp)
char *inet_ntoa (struct in_addr in)
inet_netof()
inet_lnaof()
inet_ntop()
int inet_pton(int af, const char *src, void *dst);
const char *inet_ntop(int af, const void *src,char *dst, socklen_t cnt);
issockettype(int sockfd)
gethostbyaddr()
struct hostent *gethostbyname(const char *name);
struct hostent * gethostbyaddr(const void *addr, int len, int type);
tcp全套
int listen(int sockfd,int input_queue_size)
int accept(int sockfd, struct sockaddr *addr, int *addrlen);
int send(int sockfd, const void * data, int data_len, unsigned int flags)
int recv(int sockfd, void *buf, int buf_len,unsigned int flags);
udp全套
int sendto(int sockfd, const void * data, int data_len, unsigned int flags, struct sockaddr *remaddr,sock_len remaddr_len)
int recvfrom(int sockfd, void *buf, int buf_len,unsigned int flags,struct sockaddr *from,sock_len *fromlen);