sockaddr_in && sockaddr

原创
2020/05/15 11:30
阅读数 148

sockaddr_in && sockaddr 的原型与需要包含的头文件

#include <netinet/in.h>
typedef uint32_t in_addr_t;
struct in_addr{
    in_addr_t s_addr;
 };

typedef uint16_t in_port_t;
/* Structure describing an Internet socket address.  */
struct sockaddr_in {
    __SOCKADDR_COMMON (sin_);
    in_port_t sin_port;			/* Port number.  */
    struct in_addr sin_addr;		/* Internet address.  */
    /* Pad to size of `struct sockaddr'.  */
    unsigned char sin_zero[sizeof (struct sockaddr) -
			   __SOCKADDR_COMMON_SIZE -
			   sizeof (in_port_t) -
			   sizeof (struct in_addr)];
 };

#incldude <sys/socket.h>
typedef unsigned short sa_family_t;
struct sockaddr {
	sa_family_t	sa_family;	/* address family, AF_xxx	*/
	char		sa_data[14];	/* 14 bytes of protocol address	*/
};


展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部