[GEN] Re: multiple pointers
On Sun, 15 Oct 2000, Bernie wrote:
>> On Sun, 15 Oct 2000 02:11:49 -0600, cense <cense at MAIL.RU> wrote:
>>
>> cense:
>>
>> I don't know exactly what you are trying to do, could you
>> show me a little more of the "C" function you are trying
>> to use and I will help you. Is "C" returning you a pointer to
>> a pointer of a string ? I need to see a little code.
>>
>> Bernie
Well i did not ask for help yet, but sure! Thanks for offer Bernie :)
The function im trying to wrap right now is `gethostbyname` :
// from the man page:
stuct hostent *gethostbyname( const char *name );
`gethostbyname` returns a pointer to a struct of type hostent, my first
thought was to access this struct like so:
-- Eu code
pointer hostent_ptr
pointer fake_hostent_ptr
hostent = get_hostent( ) -- this function does the `struc` call and sets it up
fake_hostent_ptr = c_func( gethostbyname_, { char_ptr } )
mem_copy( hostent_ptr, fake_hostent_ptr, sizeof( fake_hostent_ptr ) )
blah = Gets( hostent_ptr, "this" ) -- etc
-- end Eu code
Is this the correct way to get to the struct returned by `gethostbyname` ?
There probably is a more effecient way to do it.
OK, another problem:
Here is what the struct returned by `gethostbyname` looks like:
//in C
struct hostent {
char *h_name; // official name of host
char **h_aliases; // alias list
int h_addrtype; // host address type
int h_length; // length of address
char **h_addr_list; // list of addresses
};
So here is my second problem, How do i get a pointer out of a mixedlib.e
struc? I know to use Gets( ) for values. Would loc( ) be what i need to use
to get a pointer out of the struc and into a euphoria variable?
eg.
pointer my_ptr
my_ptr = loc( hostent_ptr, "h_name" )
Now would my_ptr point to the same memory that `char *h_name` in the
struc does?
Ok i know this post is getting long and disorganized but i have one more
thing to address, its related to teh above question. How do i get `char
**h_aliases` and `char **h_addr_list` into euphoria variables?
I just repeated myself basically because it should be the same as just
getting a single pointer from the struc, No?
Anyway, if you can make any sense of my rantings, than i would greatly
appreciate any feedback.
Thanks for all the help along the way Bernie. Your name is already on my
CONTRIB list for both mixedlib.e and all the help you have offered me :)
--
evil, corruption and bad taste
^cense
|
Not Categorized, Please Help
|
|