[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re:



On Mon, 5 Jun 2000, PRAKASH GOWRI wrote:

> hi everybody, 
>    
>    (1)
>  im having a problem with the gethostbyaddr function.
> i specify the
>  the arguments as :-
> 
>         127.0.0.1  for the  constant  character
> pointer,
>         4 as the size (for ipv4 address),
>         AF_INET for the family.
> 
> 
>  but i get hptr=NULL  which is the pointer to the
> hostent structure.
> i dont know if i am doing anything wrong!!!!!!!
> 
> the following code fragment  will make things
> clearer:-
>         |
>         |   
> 
> 
>   hptr=gethostbyaddr("127.0.0.1",4,AF_INET);
> 	if(hptr==NULL)
>      { 
>       printf("gethostbyaddress error for host: %s:
> %s\n",ptr,hstrerror(h_errno));
> 	printf("gethostbyaddress function return NULL,
> exiting \n");
> 	exit(0);	
>        }	
> printf("official hostaddress: %s\n",ptr);	
> 	printf("length of address= %d\n",hptr->h_length);	
> 	printf("official hostname: %s\n",hptr->h_name);
> 	for(pptr=hptr->h_aliases;*pptr!=NULL;pptr++)
> 	printf("\talias: %s\n",*pptr);
>       

Can't really tell from this distance but u might want 2 use htonl() on the
address. I came up with something like this problem when code which worked
on a Sun box wouldn't on an x86 box.

Cheers.

Alok