Site Root : gethostbyname_r

Autoconf test and demo for gethostname_r


This is a small demonstration of an autoconf test package to determine the right way to call gethostbyname_r under different oses.


  1. Add the ac_c_gethostbyname_r.m4 test to your autoconf's aclocal directory (probably in /usr/local/share/aclocal
  2. get acx_pthread.m4 from and put it in your autoconf's aclocal dir
  3. add to acconfig.h the following lines
  4. add gethostname.c to your project
  5. add gethostname.h to your project
  6. use the gethostname_re api instead of gethostbyname_r. Follow the example in test.c, note that you should initialize the variable as shown there, and do clean up after the final gethostname call as shown.

Perhaps in the future this little package should have the rest of the nonstandaized network _r calls with appropiate autoconf tests and interfaces, feel free to send on any thoughts on that.

Known to work under at least Solaris, OSF/1 and Linux

Caolan McNamara (2000) <>

Download Package

Last generated at Sun Feb 7 00:44:59 2016 Caolán McNamara <> Created with WebMake/0.5