Re: hostent address list dereferencing problem..
Jens.Toerring_at_physik.fu-berlin.de
Date: 01/28/05
- Next message: Kazman: "Interesting problem with Serial Port"
- Previous message: Norm Dresner: "Re: Can a user app hang a *IX system?"
- In reply to: BM: "hostent address list dereferencing problem.."
- Next in thread: BM: "Re: hostent address list dereferencing problem.."
- Reply: BM: "Re: hostent address list dereferencing problem.."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 28 Jan 2005 01:02:18 GMT
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
- Next message: Kazman: "Interesting problem with Serial Port"
- Previous message: Norm Dresner: "Re: Can a user app hang a *IX system?"
- In reply to: BM: "hostent address list dereferencing problem.."
- Next in thread: BM: "Re: hostent address list dereferencing problem.."
- Reply: BM: "Re: hostent address list dereferencing problem.."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|