Fixed lookup of hosts by name on win32.

This commit is contained in:
crs 2004-03-31 22:14:15 +00:00
parent 4ace26f19b
commit 4576b30c37
1 changed files with 13 additions and 3 deletions

View File

@ -675,11 +675,21 @@ CArchNetworkWinsock::nameToAddr(const std::string& name)
// address lookup // address lookup
struct hostent* info = gethostbyname_winsock(name.c_str()); struct hostent* info = gethostbyname_winsock(name.c_str());
if (info == NULL) { if (info == NULL) {
delete addr;
throwNameError(getsockerror_winsock()); throwNameError(getsockerror_winsock());
} }
addr = CArchNetAddressImpl::alloc(info->h_length);
memcpy(TYPED_ADDR(void, addr), info->h_addr_list[0], info->h_length); // copy over address (only IPv4 currently supported)
if (info->h_addrtype == AF_INET) {
addr = CArchNetAddressImpl::alloc(sizeof(struct sockaddr_in));
memcpy(&inaddr.sin_addr, info->h_addr_list[0],
sizeof(inaddr.sin_addr));
memcpy(TYPED_ADDR(void, addr), &inaddr, addr->m_len);
}
else {
throw XArchNetworkNameUnsupported(
"The requested name is valid but "
"does not have a supported address family");
}
} }
return addr; return addr;