hostent address list dereferencing problem..
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > hostent address list dereferencing problem..




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    hostent address list dereferencing problem..  
BM


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-27-05 10:52 PM

Hi all,

i'm having problems grabbing the IP out of the h_addr_list (or h_addr)
sturct on a
freshly gethostbyname'd hostent structure.

observe:

struct  in_addr **address;

......

if((h=gethostbyname(node)) == NULL) {
herror("gethostbyname");
exit(1);
}

address=(struct in_addr **)h->h_addr;

for(; *address != NULL; address++);
printf("addr: %s\n",*address);
exit(1);


just to purely see if I can get the address..
I am unable to get the IP...

can anyone help pls?

thanks

bm






[ Post a follow-up to this message ]



    Re: hostent address list dereferencing problem..  
Fletcher Glenn


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-27-05 10:52 PM


"BM" <b.marsh@gmx.net> wrote in message
news:1106858791.993371.9910@z14g2000cwz.googlegroups.com...
> Hi all,
>
> i'm having problems grabbing the IP out of the h_addr_list (or h_addr)
> sturct on a
> freshly gethostbyname'd hostent structure.
>
> observe:
>
> struct  in_addr **address;
>
> ......
>
> if((h=gethostbyname(node)) == NULL) {
> herror("gethostbyname");
> exit(1);
> }
>
> address=(struct in_addr **)h->h_addr;
>
> for(; *address != NULL; address++);
> printf("addr: %s\n",*address);
> exit(1);
>
>
> just to purely see if I can get the address..
> I am unable to get the IP...
>
> can anyone help pls?
>
> thanks
>
> bm
>

Your printf is incorrect. If you want to print it, you need to do a
inet_ntoa(*address).
As in printf("addr: %s\n", inet_ntoa(*address));

--

Fletcher Glenn







[ Post a follow-up to this message ]



    Re: hostent address list dereferencing problem..  
Jens.Toerring@physik.fu-berlin.de


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-28-05 01:48 AM

BM <b.marsh@gmx.net> wrote:
> i'm having problems grabbing the IP out of the h_addr_list (or h_addr)
> sturct on a
> freshly gethostbyname'd hostent structure.

> struct  in_addr **address;

> if((h=gethostbyname(node)) == NULL) {
> herror("gethostbyname");
> exit(1);
> }

> address=(struct in_addr **)h->h_addr;

You need

address = ( struct in_addr ** ) h->h_addr_list;

h_addr is just defined to h_addr_list[ 0 ].

> for(; *address != NULL; address++);

Here you've got a semicolon at the end of the line that definitely
shouldn't be there...

> printf("addr: %s\n",*address);

Whats pointed to by address isn't a simple string so you need

printf( "addr = %s\n", inet_ntoa( *address );

to convert it to a string in numbers-and-dots notation.

Regards, Jens
--
\   Jens Thoms Toerring  ___  Jens.Toerring@physik.fu-berlin.de
\__________________________  http://www.toerring.de





[ Post a follow-up to this message ]



    Re: hostent address list dereferencing problem..  
BM


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-28-05 07:47 AM

All, thanks for your help.

Interestingly enough, inet_ntop didnt work; i had to indeed use
inet_ntoa. Hmm, i will dig round the manpages to suss this out.
thanks again all.

bry.






[ Post a follow-up to this message ]



    Re: hostent address list dereferencing problem..  
Jens.Toerring@physik.fu-berlin.de


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-28-05 12:52 PM

BM <b.marsh@gmx.net> wrote:
> Interestingly enough, inet_ntop didnt work; i had to indeed use
> inet_ntoa. Hmm, i will dig round the manpages to suss this out.

Show us how you tried to invoke inet_ntop(), perhaps we can help...

Regards, Jens
--
\   Jens Thoms Toerring  ___  Jens.Toerring@physik.fu-berlin.de
\__________________________  http://www.toerring.de





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 10:23 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register