由于某些原因,我的指针需要指向sockaddr而不是sockaddr_in,为了使用sin_family,sin_pot和sin_addr与sockaddr指针,我怎么能转换这两个结构? 这是我的代码
static int proxy_getaddr(char *HostName, int Port, SockAddrType *Result)
.......
Result->sin_family=AF_INET;
Result->sin_port=htons((unsigned short)Port);
........
memcpy((char*)&Result->sin_addr,(char*)Host->h_addr,sizeof(Result->sin_addr));
正如您可能看到我需要转换的指针是结果,我的控制台错误是
‘const struct sockaddr’ has no member named ‘sin_family’
‘const struct sockaddr’ has no member named ‘sin_port’
‘const struct sockaddr’ has no member named ‘sin_addr’