Internet Address To IP Address

Posted on 2004-09-10
Last Modified: 2010-04-01
Is there a way I can get the IP address from an internet address usinging Winsocks.  I.E.  


Question by:kipp8r
  • 3
LVL 30

Expert Comment

ID: 12030573
The gethostbyname subroutine retrieves host address and name information using a host name as a search key.
LVL 30

Accepted Solution

Axter earned 200 total points
ID: 12030598
char acClientHost[255];
WORD wVersionRequested;
WSADATA wsaData;
struct hostent *pHostent = NULL;
wVersionRequested = MAKEWORD( 1, 1);

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

    if  (   dwErr =   gethostname (   ( char *) acClientHost, 255))
            return  (   nWSockRC);

if (!(pHostent = gethostbyname ( acClientHost)))
 // an error occured...
 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);
LVL 30

Expert Comment

ID: 12030623
Above code was copied and pasted from following link:

See also following links:

Author Comment

ID: 12049751
Thank You Axter!!

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now