IP Address
-
Hai Friends, How can i get the IP addrees of the current system. Plase anyone give me a step by step procedure
Hello, I've done this before using windows sockets. I don't know if it's the best way, but it definitely works: char szHostName[400]; struct hostent *hostinfo = NULL; IN_ADDR addr; char szIP[16]; // "xxx.xxx.xxx.xxx\0" ULONG ulIP = 0; // get the dns name as a string gethostname(szHostName, 400); // get the host info (contains ip address) hostinfo = gethostbyname(szHostName); if(hostinfo == NULL) { DWORD dwError = WSAGetLastError(); // handle the error } else { // get the ip as ULONG ulIP = *reinterpret_cast(hostinfo->h_addr_list[0]); // put the ip it into an IN_ADDR addr.S_un.S_addr = ulIP; // changes ip into string sprintf(szIP, "%s", inet_ntoa(addr)); TRACE("My IP address is %s\n", szIP); } Regards, Simon
-
Hello, I've done this before using windows sockets. I don't know if it's the best way, but it definitely works: char szHostName[400]; struct hostent *hostinfo = NULL; IN_ADDR addr; char szIP[16]; // "xxx.xxx.xxx.xxx\0" ULONG ulIP = 0; // get the dns name as a string gethostname(szHostName, 400); // get the host info (contains ip address) hostinfo = gethostbyname(szHostName); if(hostinfo == NULL) { DWORD dwError = WSAGetLastError(); // handle the error } else { // get the ip as ULONG ulIP = *reinterpret_cast(hostinfo->h_addr_list[0]); // put the ip it into an IN_ADDR addr.S_un.S_addr = ulIP; // changes ip into string sprintf(szIP, "%s", inet_ntoa(addr)); TRACE("My IP address is %s\n", szIP); } Regards, Simon
-
Hai, Thanks for your message. But when i copy the given code lot of errors occured. IN_ADDR undeclared identifier etc. I have not insatlled Platform SDK. For running the code may i need the Paltform SDK? regards Anish