Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
platform
active.directory
adsi
adsi.iis-admin
base
com_ole
complus_mts
component_svcs
database
directx
gdi
graphics_mm
internet.client
internet.server
internet.server.isapi-dev
localization
mapi
messaging
msi
mslayerforunicode
multimedia
networking
networking.ipv6
sdk_install
security
shell
telephony.tapi_2
telephony.tapi_3
telephony.tsp
telephony.wte
tools
ui
ui_shell
win_base_svcs
win16
  
 
date: Thu, 31 Jul 2008 03:37:47 -0700 (PDT),    group: microsoft.public.platformsdk.networking.ipv6        back       


How to get the IP address in network byte order   
Hi,

Currently I have the following code to get the IP address in network
byte order,

unsigned int getIP(char *sHostName)
{
   PHOSTENT ph;
   unsigned int nAddr = inet_addr( sHostName );
   if(nAddr == INADDR_NONE) /* hostname is in name format */
   {
      ph = gethostbyname(sHostName);
      nAddr = *(unsigned int*)( ph->h_addr_list[0];
   }
   else /* hostname is in x.x.x.x format */
   {
      ph = gethostbyaddr( (const char*)&nAddr, 4, PF_INET );
      nAddr = *(unsigned int*)( ph->h_addr_list[0] ) ;
   }
   return nAddr;
}

Going forward for IPv6, since these structures and functions are
deprecated, I have to replace PHOSTENT, gethostbyname, gethostbyaddr
and inet_addr by newer functions. I have been trying to achieve the
same using getaddrinfo, but the results are not the same.

Can anyone tell me how do we get the ip address in network byte order
by using getaddrinfo function or any other function which is IPv6
compliant

Thanks.
date: Thu, 31 Jul 2008 03:37:47 -0700 (PDT)   author:   ipv6

RE: How to get the IP address in network byte order   
"ipv6" wrote:

> Hi,
> 
> Currently I have the following code to get the IP address in network
> byte order,
> 
> unsigned int getIP(char *sHostName)
> {
>    PHOSTENT ph;
>    unsigned int nAddr = inet_addr( sHostName );
>    if(nAddr == INADDR_NONE) /* hostname is in name format */
>    {
>       ph = gethostbyname(sHostName);
>       nAddr = *(unsigned int*)( ph->h_addr_list[0];
>    }
>    else /* hostname is in x.x.x.x format */
>    {
>       ph = gethostbyaddr( (const char*)&nAddr, 4, PF_INET );
>       nAddr = *(unsigned int*)( ph->h_addr_list[0] ) ;
>    }
>    return nAddr;
> }
> 
> Going forward for IPv6, since these structures and functions are
> deprecated, I have to replace PHOSTENT, gethostbyname, gethostbyaddr
> and inet_addr by newer functions. I have been trying to achieve the
> same using getaddrinfo, but the results are not the same.
> 
> Can anyone tell me how do we get the ip address in network byte order
> by using getaddrinfo function or any other function which is IPv6
> compliant
> 
> Thanks.
>
date: Tue, 26 Aug 2008 02:05:00 -0700   author:   mrhacker

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us