Thanks for the reply. I tried everything that you said and checked that the length passed to the function was correct this time but it still returns NULL. Error returned by WSAGetLastError() is as follows and description from msdn:
Valid name, no data record of requested type.
The requested name is valid and was found in the database, but it does not have the correct associated data being resolved for. The usual example for this is a host name-to-address translation attempt (using gethostbyname or WSAAsyncGetHostByName) which uses the DNS (Domain Name Server). An MX record is returned but no A record—indicating the host itself exists, but is not directly reachable.
I am posting the whole code. Maybe the error is elsewhere. I'll read the website where I got this again just in case:
Thanks for the help everybody. I really appreciate it.
string ip_address = "127.0.0.1";
const char *ip_address_char= ip_address.c_str();
int length = strlen(ip_address.c_str());
hostent *server_ip_address = gethostbyaddr(ip_address.c_str(),strlen(ip_address.c_str()),AF_INET);
int err = WSAGetLastError();
server.sin_addr.S_un.S_addr /*=*((unsigned long*)server_ip_address->h_addr);*/= (u_long) server_ip_address->h_addr_list;
server.sin_family = AF_INET;
server.sin_port = htons((u_short)20248);
const char *output_message = "test";
int y = 0;
cout << input_message << "/n";