sockaddr_in与sockaddr区别

先粘代码

struct sockaddr { __SOCKADDR_COMMON (sa_); /* Common data: address family and length. */ char sa_data[14]; /* Address data. */ };   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)];   };   sockaddr_in与sockaddr区别

 

 其在内存占用上是一致的,区别在于sockaddr_in可以详细设置端口号和IP地址,相互之间可以进行强制类型转化

上一篇:Socket通信原理


下一篇:传输层协议UDP简介