i posted this thread after searching on net...

now if u have any matter directly related to the topic....post it..

IPv4: man gethostbyname http://www.freebsd.org/cgi/man.cgi?query=gethostbyname&sektion=3&apropos=0&manpath=FreeBSD+7.0-stable

IPv6 and other address families: gethostbyname2 getaddrinfo http://www.freebsd.org/cgi/man.cgi?query=getaddrinfo&sektion=3&apropos=0&manpath=FreeBSD+7.0-stable

// IPv4 address lookup
#include <netdb.h>
#include <arpa/inet.h>
#include <iostream>

int main()
{
  const char* const host = "www.toolbar.google.com" ;
  const hostent* host_info = 0 ;

  for( int attempt=0 ; (host_info==0) && (attempt<3) ; ++attempt )
    host_info = gethostbyname(host) ;

  if(host_info)
  {
    std::cout << "host: " << host_info->h_name << '\n' ;

    for( int i=0 ; host_info->h_aliases[i] ; ++i )
      std::cout << " aka: " << host_info->h_aliases[i] << '\n' ;

    for( int i=0 ; host_info->h_addr_list[i] ; ++i )
    {
      const in_addr* address = (in_addr*)host_info->h_addr_list[i] ;
      std::cout << " address: " << inet_ntoa( *address ) << '\n' ;
    }
  }
  else herror( "error" ) ;
}
This article has been dead for over six months. Start a new discussion instead.