🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Get IP Address

Started by
1 comment, last by Dealerz 23 years, 4 months ago
Hi, i''ve been trying to get the numerical ip address of you computer when you connect to the internet. I''ve tried gethostname() it returns a string and then when I try and call gethostbyname() I just get the string of the name that the IP would resoulve to but not the actual ip address. Could someone please help me out.
Advertisement
If you have a hostname of the actual IP you can simply resolve it using one of the winsock functions. Its that function that you use before you connect to a server like "yahoo.com" to resolve it into a sockaddr struct or a string representing the numerical IP.
CorsairK8@Fnemesis.comLinux Debian/GNU RulezThis is my signitory!C Is Tha Best!
char hostname[256];struct hostent *host;in_addr ip;gethostname(hostname, 256);host = gethostbyname(hostname);memcpy(&ip, host->h_addr, sizeof(ip));printf("First host IP is: %s\n", inet_ntoa(ip)); 


-Mike
-Mike

This topic is closed to new replies.

Advertisement