Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Obtaining IP address
#1
I know in QM's Options/Security/Network Dialog the display shows the computer's IP address. How do you get it? I looked through MSDN but couldn't find it. Thanks.
Matt
Matt B
#2
Visual Basic example in MSDN knowledge base:

http://support.microsoft.com/default.asp...-us;160215


And QM internal function in C++:


bool GetLocalPCNameAndAddress(CStr& sn, CStr& sa)
{
if(!g_wsg.Init()) return 0;
char strHost[MAX_PATH] = { 0 };
if(gethostname(strHost, sizeof(strHost))==SOCKET_ERROR) return 0;
hostent* hp = gethostbyname(strHost);
if(hp && Len1(hp->h_name)) sn=hp->h_name;
else if(Len1(strHost)) sn=strHost;
else return 0;

int i;
sa="";
for(i=0; hp && hp->h_addr_list[i] && hp->h_length>=4; i++)
{
if(sa.len) sa+=", ";
sa.FormA("%u.%u.%u.%u",
(UINT)(((PBYTE) hp->h_addr_list[i])[0]),
(UINT)(((PBYTE) hp->h_addr_list[i])[1]),
(UINT)(((PBYTE) hp->h_addr_list[i])[2]),
(UINT)(((PBYTE) hp->h_addr_list[i])[3]));
}
if(sa=="127.0.0.1") sa="";
return 1;
}

Here CStr is same as str in QM, Len1 can be replaced to len, FormA to formata. Instead of g_wsg.Init use something like this:

WSADATA wsaData; WSAStartup(0x101,&wsaData);

And finally call WSACleanup();

Functions, types and constants are not defined in QM, so you would have to search in MSDN and convert to QM.


Forum Jump:


Users browsing this thread: 1 Guest(s)