|
-
May 8th, 1999, 08:30 AM
#1
Winsock <-> IP
I'm programming using VC++ 5.0.
The program I'm writing is for both win95 and 98.
The part of the program should show IP number of the computer.
What is the best way to get IP adress, without external dlls'? So far, I have used:
char szHostName[128];
struct hostent * pHost;
CString str = "";
int nCheck = 0;
WSADATA wsaData;
/*
WSAStartup (MAKEWORD( 1, 0 ), &wsaData);
nCheck = gethostname (szHostName, 128);
if( gethostname (szHostName, 128) == 0 ) {
// Get host adresses
int i;
pHost = gethostbyname(szHostName);
for( i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++
int j;
for( j = 0; j < pHost->h_length; j++ ) {
CString addr;
if( j > 0 ) str += ".";
addr.Format("%u", (unsigned int)((unsigned
char*)pHost->h_addr_list[i])[j]);
str += addr;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|