Home > Archive > Unix Programming > January 2005 > hostent address list dereferencing problem..
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
hostent address list dereferencing problem..
|
|
|
| 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
| |
| Fletcher Glenn 2005-01-27, 8:58 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
| |
| Jens.Toerring@physik.fu-berlin.de 2005-01-28, 3:58 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
| |
|
| 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.
| |
| Jens.Toerring@physik.fu-berlin.de 2005-01-28, 4:00 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
|
|
|
|
|