small bugfix for std.socket; use reentrant gethostbyname

Downs default_357-line at yahoo.de
Sun Mar 18 13:07:33 PDT 2007


483,485c485,489
<         hostent* he = gethostbyname(toStringz(name));
<         if(!he)
<             return false;
---
 >         hostent he_buf;
 >         char[4096] buffer; int error;
 >         hostent *he;
 >         if (gethostbyname_r(toStringz(name), &he_dump, buffer.ptr, buffer.length, &he, &error)!=0) return false;

Also, the old way would cause a problem .. because as the manpage for
gethostbyname will verify, if he != 0 doesn't mean there's no error ..
that's what h_errno is for. A return value of 0 from gethostbyname_r,
however, does guarantee there's no error.
(The problem with the return value would cause an error later on,
  where populate had to work with an invalid struct - that's how I
  found it in the first place)

Greetings --downs


More information about the D.gnu mailing list