Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Internet Addresses in MFC

Posted on 1998-11-14
3
Medium Priority
?
193 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:MattLesko
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
ID: 1324705
Use the Winsock function 'gethostbyname()'. It returns a 'struct HOSTENT' which has a member called 'h_addr' that holds the IP in binary form (network byte order!). If you need an example how to use it, feel free to ask...
0
 

Author Comment

by:MattLesko
ID: 1324706
Sorry, but being new at this, I'd like to request a sample.
0
 
LVL 86

Expert Comment

by:jkr
ID: 1324707
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);
}
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question