I have been trying to do this in ms visual studio 2008 using the winsock2 package but whenever i try to resolve the input ip address, which is valid, I get an "Invalid ip..." error. My only guess is that there is some permissions error, but I really have no clue whats wrong. Please help!
if(WSAStartup(MAKEWORD(2,2), &wsaData) != 0){
error("WSAStartup() failed\n\r");
}
// validate port
if( port <= 0 || port > 65535){
sprintf(msg, "Invalid port - %d. Ports must be between 0 and 65536\n\r",
port);
error(msg);
}
// validate ip
inet_addr = inet_addr(ip);
if( inet_addr == INADDR_NONE){
sprintf(msg, "Not an ip - %s\n\r", ip);
error(msg);
} else {
info = gethostbyaddr((char*)&inet_addr, 4, PF_INET);
if(info == NULL){
sprintf(msg, "Invalid ip - %s\n\r", ip);
error(msg);
}
}