As the subject suggests, I''m trying to figure out the IP of the local machine. I''ve figured out how to get the host name, but I can''t seem to resolve it to an IP without crashing Any way to get just the IP? Thanks.
--------------------
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor
Local machine IP address with Winsock
try this:
#include <iostream>#include <windows.h>using namespace std;#pragma comment(lib,"ws2_32.lib")void main(){ WSADATA wsData; ::WSAStartup(MAKEWORD(2,2),&wsData); char name[512]; ::gethostname(name,512); hostent* phost = ::gethostbyname(name); sockaddr_in addr; ::memset(&addr,0,sizeof(addr)); ::memcpy(&(addr.sin_addr.s_addr),phost->h_addr,4); char* ip = ::inet_ntoa(addr.sin_addr); cout << name << ", ip: " << ip << endl; ::WSACleanup();}
Thanks for the quick reply. Ok, I tried that and it crashes It is very similar to the code I myself wrote. Did I mention I''m writing this app for Windows Pocket PC 2000/2002? I''m not sure if that''ll make a difference... any other ideas?
--------------------
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor
--------------------
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor
well, shit. that would have helped The above''ll work for full-blown Windows. I have NO idea how to go about it on a pocketPC
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement