It works!
What I ended up having to do was cast between a winsock 1 and winsock 2 structure to get access to the in_addr structure that the inet_ntoa function needed.
Here is my working code:
Code:
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
return;
}
char host[255];
char *hostname=&host[0];
memset(hostname,NULL,255);
gethostname(hostname,255);
struct addrinfo *res = NULL;
int rc;
char *port=new char[25];
memset(port,NULL,25);
strcpy(port,"7");
rc = getaddrinfo(hostname,port,NULL,&res);
if (rc != 0)
fprintf(stderr, "Invalid address %s, getaddrinfo failed: %d\n", hostname, rc);
struct sockaddr_in *myip;
myip=(sockaddr_in *)res->ai_addr;
char *ipaddr=new char[16];
memset(ipaddr,NULL,16);
sprintf(ipaddr,"%s",inet_ntoa( myip->sin_addr ));
delete [] ipaddr;
delete [] port;