Hostent extension problem - returning the ip address


(Berger, Daniel) #1

I was guessing, actually - I knew that didn’t work, I merely put it there as
an “alert” of sorts to point you to the area where I’m having trouble.

Also, the eventual plan is to use the thread-safe versions provided by
individual vendors, e.g. gethostbyname_r() on Solaris. I thought I would
start with a basic version and work my way up from there. :slight_smile:

Regards,

Dan

···

-----Original Message-----
From: ts [mailto:decoux@moulon.inra.fr]
Sent: Tuesday, June 11, 2002 10:26 AM
To: ruby-talk@ruby-lang.org
Cc: ruby-talk@ruby-lang.org
Subject: Re: hostent extension problem - returning the ip address

Data_Wrap_Struct(cHost,0,host_free,hp);
[…]
hp = gethostbyname(h);
pptr = hp->h_addr_list;
Data_Wrap_Struct(cHost,0,host_free,pptr); /* problem here? */

Why do you use Data_Wrap_Struct() ?

On Solaris 8, for gethostbyname(3)

 The functions gethostbyname(), gethostbyaddr(), and  gethos-
 tent()  use static storage that is reused in each call, mak-
             ^^^^^^^^^^^^^^
 ing these functions unsafe for use in multi-threaded  appli-
 cations.

Guy Decoux


(ts) #2

Also, the eventual plan is to use the thread-safe versions provided by
individual vendors, e.g. gethostbyname_r() on Solaris. I thought I would
start with a basic version and work my way up from there. :slight_smile:

Well, even if you use gethostname_r() you must first allocate the struct
and the buffer. You call gethostname_r(), create the result
(rb_str_new2()), free the struct and buffer and return the result or call
rb_yield(). You don't need a Data_Wrap_Struct()

Guy Decoux