首页 > 代码库 > UNIX网络编程-函数原型

UNIX网络编程-函数原型

 

#include <netinet/in.h>
struct in_addr {
in_addr_t s_addr; /* 32-bit IPv4 address */
}; /* network byte ordered */

struct sockaddr_in {
unit8_t sin_len; /* length of structure (16) */
sa_family_t sin_family; /* AF_INET */
in_port_t sin_port; /* 16-bit TCP or UDP port number */
/* network byte ordered */
struct in_addr sin_addr; /* 32-bit IPv4 address */
/* network byte ordered */
char sin_zero[8]; /* unused */
};

/* ============================================================================================================================ */
#include <arpa/inet.h>

int inet_aton(const char *strptr, struct in_addr *addrptr);
返回:若字符串有效则为1,否则为0

in_addr_t inet_addr(const char *strptr);
返回:若字符串有效则为32位二进制网络字节序的IPv4地址,否则为INADDR_NONE

char *inet_ntoa(struct in_addr inaddr);
返回:指向一个点分十进制数串的指针

/* =========================================================================================================================== */
#include <sys/socket.h>

ssize_t recvfrom(int sockfd, void *buff, size_t nbytes, int flags, struct sockaddr *from, socklen_t *addrlen);

ssize_t sendto(int sockfd, const void *buff, size_t nbytes, int flags, const struct sockaddr *to, socklen_t addrlen);

返回:若成功则为读或写的字节数,若出错则为-1