由于某些原因,我的指针需要指向 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’