Socket中的地址结构体

typedef unsigned short int sa_family_t;

#define	__SOCKADDR_COMMON(sa_prefix) sa_family_t sa_prefix##family

#define __SOCKADDR_COMMON_SIZE		 (sizeof (unsigned short int))

/* Structure describing a generic socket address.  */
struct sockaddr
{
    __SOCKADDR_COMMON (sa_);	/* Common data: address family and length.  */
    char sa_data[14];			/* Address data.  */
};


/* Type to represent a port.  */
typedef uint16_t in_port_t;

/* Internet address.  */
typedef uint32_t in_addr_t;
struct in_addr
{
	in_addr_t s_addr;
};

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)];
};

posted @ 2018-03-11 12:46  酱油和醋  阅读(205)  评论(0编辑  收藏  举报