Re: C Socket Programming question
From: Justin Robbs (justin_robbsNO_at_SPAMhotmail.com)
Date: 11/12/03
- Next message: Barry Margolin: "Re: C Socket Programming question"
- Previous message: Alexey A. Kiritchun: "Re: Buffering in pipes"
- In reply to: William Ahern: "Re: C Socket Programming question"
- Next in thread: Barry Margolin: "Re: C Socket Programming question"
- Reply: Barry Margolin: "Re: C Socket Programming question"
- Reply: William Ahern: "Re: C Socket Programming question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 12 Nov 2003 14:17:50 -0700
> gethostbyname(3) is returning a statically allocated struct hostent.
>
> Two approaches: Write a routine to deep-copy each struct hostent returned
> from gethostbyname(3);
By deep copy you mean something like this:
struct hostent *tmp_host;
/* this is how the hostent is struct is laid out in netdb.h on my system */
struct
{
char *h_name;
char **h_aliases;
int h_addrtype;
int h_length;
int **h_addr_list;
#define h_addr h_addr_list [0];
} remote_reg [MAXREGISTERS];
if( ( tmp_host = gethostbyname( Remote_Reg ) ) == NULL )
{
sprintf(error_msg_1,"Error Sending Socket: ");
sprintf(error_msg_2,"Unable to get remote register");
error_codes(694);
}
remote_reg [i] = tmp_host;
Then when I am sending I would do something like this:
struct sockaddr_in host1_addr;
host1_addr.sin_addr = *( (struct in_addr *)remote_reg [i]->h_addr );
I omitted all but the necessary code for the sake of brevity, but is this
what you are suggesting since I don't have gethostbyname_r ()?
Thanks to both William and Barry for their suggestions, and to anyone else
who posts. BTW, my man page for gethostbyname doesn't mention the hostent
structure being static. Since you guys mentioned it I can see that is
definitely what is happening. It just would have been nice for them to have
put that on there.
Thanks,
Justin
- Next message: Barry Margolin: "Re: C Socket Programming question"
- Previous message: Alexey A. Kiritchun: "Re: Buffering in pipes"
- In reply to: William Ahern: "Re: C Socket Programming question"
- Next in thread: Barry Margolin: "Re: C Socket Programming question"
- Reply: Barry Margolin: "Re: C Socket Programming question"
- Reply: William Ahern: "Re: C Socket Programming question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|