Call gethostbyname with FFI?

Bert Freudenberg bert at isgnw.CS.Uni-Magdeburg.De
Fri Feb 11 13:47:12 UTC 2000


On Thu, 10 Feb 2000, John Clonts wrote:

> Lex Spoon wrote:
> > 
> > Of course, duh, the right thing to do is fix that primitive, not lop
> > more code on top of it to work around it.  
> 
> I think through my inquiries here I have determined that the primitive
> is not broken, but some nuance of my system is causing the problem
> (though when called from a c++ prog it works ok).  Thus a good exercise
> for gee-whiz value for ffi, and if it works then it (also) buys me more
> time till I have to upgrade my Linux version on this machine....

*Please* try to modify the primitive as I suggested before. It would help
us all and hopefully noone steps into this ever again. The change I had in
mind is somewhat like this (in sqUnixNetwork.c):

static int nameToAddr(char *hostName)
{
  struct hostent *he;
  he = gethostbyname(hostName);
  lastError= h_errno;			/* ditto */
  if (h_errno) {
    fprintf(stderr, "error: gethostbyname(%s) -> h_errno=%i\n",
	    hostName, h_errno);
    herror("description");
    return 0;
  }
  return ntohl(*(long *)(he->h_addr_list[0]));
}

This should tell you what the problem is.

> So, can you tell me how to specify the 'struct hostent' return value as
> an External[Something] and thence dereference the contained char **
> h_addr_list?

I'll sent a class in a separate message.

  -Bert-







More information about the Squeak-dev mailing list