Link to home
Start Free TrialLog in
Avatar of MattLesko
MattLesko

asked on

Internet Addresses in MFC

How would I go about taking a string (like "www.microsoft.com") and converting it into the dotted decimal system (like 127.0.0.1). Java has the function .getByName(), but I don't see that anywhere in VC++ 66.0. Any suggestions? TIA, Matt Lesko
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MattLesko
MattLesko

ASKER

Sorry, but being new at this, I'd like to request a sample.
No problem ;-)
Here's your example:

WORD            wVersionRequested;
WSADATA            wsaData;
struct hostent      *pHostent = NULL;      
 
wVersionRequested = MAKEWORD( 1, 1);

if ( nErr = WSAStartup ( wVersionRequested, &wsaData))
{
  // error initializing winsck...      
}


if (!(pHostent = gethostbyname ( "www.microsoft.com")))
{
 // an error occured...
}
else
{
 printf ( "IP: %s\n", BinIP2StrIP ( *(( long *)  pHostent->h_addr));
}


char *BinIP2StrIP ( long lnIP)
{
static char s_acStrIP [      16];

PUCHAR      puc = ( unsigned char *) &lnIP;
unsigned int aun [ 4];

for ( int i = 0; i < 4; aun [ i++] = *puc++);

sprintf      ( s_acStrIP, "%d.%d.%d.%d", aun [ 0], aun [ 1], aun [ 2], aun [ 3]);

return ( s_acStrIP);
}