johnclarke
asked on
Obtaining a machines IP Address
I need a routine that gets the IP address of the machine that the program is currently running on. The compiler that I am using is Microsoft Visual C Version 6.
I would be grateful for all advice offered regarding this.
Thanks in advance
John
I would be grateful for all advice offered regarding this.
Thanks in advance
John
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
char buffer[255];
gethostname(buffer,sizeof(
struct hostent *host = gethostbyname(buffer);
memcpy((char*)&our_addr.si
then to convert to dotted decimal
char * inet_ntoa(our_addr.sin_add
dont free the pointer that the above function returns as its from winsocks own heap and winsock maanages that. also if you want the ip address make sure you make a pysical copy of it to another memory location as the next winsock call may overwrite the original (see the winsock help for more info on this)