当前位置: 技术问答>linux和unix
IPv4 套接字地址结构转换(char to struct sockaddr_in) 看不懂
来源: 互联网 发布时间:2016-12-08
本文导语: 本帖最后由 jameszhanglei123 于 2011-04-25 18:27:51 编辑 class TcpSockAddr { public: ............. public: int ai_family; char ai_addr[24]; // ipv6's length is 24 bytes } TcpSockAddr::TcpSockAddr(int family) { ai_family = family; bzero((void *)&ai_addr, si...
{
public:
.............
public:
int ai_family;
char ai_addr[24]; // ipv6's length is 24 bytes
}
TcpSockAddr::TcpSockAddr(int family)
{
ai_family = family;
bzero((void *)&ai_addr, sizeof(ai_addr));
if(ai_family == AF_INET){
ai_addrlen = sizeof(struct sockaddr_in);
((struct sockaddr_in*)&ai_addr)->sin_family = AF_INET;
}
这行为什么不是 ((struct sockaddr_in*)ai_addr)->sin_family = AF_INET;
有点看不懂
|
效果一样吧
对于数组而言,其名称自身就表示一个地址
所以,ai_addr与&ai_addr的值完全一样
对于数组而言,其名称自身就表示一个地址
所以,ai_addr与&ai_addr的值完全一样