You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by ne...@thewrittenword.com on 2001/08/09 12:46:40 UTC

APR_CHECK_GETHOSTBYNAME_R_STYLE (ick)

Between Solaris, HP-UX, AIX, Tru64 UNIX, and IRIX, there are three
possibilities for the number of arguments to gethostbyname_r: 3, 5, 6.

I think the test to determine the number of arguments in
apr_network.m4 is inadequate. The ones used by the cURL program
(http://curl.haxx.se) seem far more robust in that it uses AC_TRY_RUN
to determine the correct number of arguments rather than a modified
AC_TRY_COMPILE.

I'll try and have a patch over the weekend. The autoconf test used by
curl is attached (curl is dual licensed under the MPL and a
MIT/X-derivate so it's ok to steal).

-- 
albert chin (china@thewrittenword.com)

-- snip snip
AC_DEFUN(CURL_CHECK_GETHOSTBYNAME_R,
[
  dnl check for number of arguments to gethostbyname_r. it might take
  dnl either 3, 5, or 6 arguments.
  AC_CHECK_FUNCS(gethostbyname_r,[
    AC_MSG_CHECKING(if gethostbyname_r takes 3 arguments)
    AC_TRY_RUN([
#include <string.h>
#include <sys/types.h>
#include <netdb.h>

int
main () {
struct hostent h;
struct hostent_data hdata;
char *name = "localhost";
int rc;
memset(&h, 0, sizeof(struct hostent));
memset(&hdata, 0, sizeof(struct hostent_data));
rc = gethostbyname_r(name, &h, &hdata);
exit (rc != 0 ? 1 : 0); }],[
      AC_MSG_RESULT(yes)
      AC_DEFINE(HAVE_GETHOSTBYNAME_R_3)
      ac_cv_gethostbyname_args=3],[
      AC_MSG_RESULT(no)
      AC_MSG_CHECKING(if gethostbyname_r with -D_REENTRANT takes 3
arguments)
      AC_TRY_RUN([
#define _REENTRANT

#include <string.h>
#include <sys/types.h>
#include <netdb.h>

int
main () {
struct hostent h;
struct hostent_data hdata;
char *name = "localhost";
int rc;
memset(&h, 0, sizeof(struct hostent));
memset(&hdata, 0, sizeof(struct hostent_data));
rc = gethostbyname_r(name, &h, &hdata);
exit (rc != 0 ? 1 : 0); }],[
        AC_MSG_RESULT(yes)
        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3)
        AC_DEFINE(NEED_REENTRANT)
        ac_cv_gethostbyname_args=3],[
        AC_MSG_RESULT(no)
        AC_MSG_CHECKING(if gethostbyname_r takes 5 arguments)
        AC_TRY_RUN([
#include <sys/types.h>
#include <netdb.h>

int
main () {
struct hostent *hp;
struct hostent h;
char *name = "localhost";
char buffer[8192];
int h_errno;
hp = gethostbyname_r(name, &h, buffer, 8192, &h_errno);
exit (hp == NULL ? 1 : 0); }],[
          AC_MSG_RESULT(yes)
          AC_DEFINE(HAVE_GETHOSTBYNAME_R_5)
          ac_cv_gethostbyname_args=5],[
          AC_MSG_RESULT(no)
          AC_MSG_CHECKING(if gethostbyname_r takes 6 arguments)
          AC_TRY_RUN([
#include <sys/types.h>
#include <netdb.h>

int
main () {
struct hostent h;
struct hostent *hp;
char *name = "localhost";
char buf[8192];
int rc;
int h_errno;
rc = gethostbyname_r(name, &h, buf, 8192, &hp, &h_errno);
exit (rc != 0 ? 1 : 0); }],[
            AC_MSG_RESULT(yes)
            AC_DEFINE(HAVE_GETHOSTBYNAME_R_6)
            ac_cv_gethostbyname_args=6],[
            AC_MSG_RESULT(no)
            have_missing_r_funcs="$have_missing_r_funcs gethostbyname_r"],
            [ac_cv_gethostbyname_args=0])],
          [ac_cv_gethostbyname_args=0])],
        [ac_cv_gethostbyname_args=0])],
      [ac_cv_gethostbyname_args=0])])

Re: APR_CHECK_GETHOSTBYNAME_R_STYLE (ick)

Posted by Sterling Hughes <st...@designmultimedia.com>.
On Fri, 10 Aug 2001, Sterling Hughes wrote:

> On Thu, 9 Aug 2001, Justin Erenkrantz wrote:
>
> > [ This message belongs at dev@apr.apache.org not new-httpd ]
> >
> > On Thu, Aug 09, 2001 at 05:46:40AM -0500, new-httpd@thewrittenword.com wrote:
> > > Between Solaris, HP-UX, AIX, Tru64 UNIX, and IRIX, there are three
> > > possibilities for the number of arguments to gethostbyname_r: 3, 5, 6.
> > >
> > > I think the test to determine the number of arguments in
> > > apr_network.m4 is inadequate. The ones used by the cURL program
> > > (http://curl.haxx.se) seem far more robust in that it uses AC_TRY_RUN
> > > to determine the correct number of arguments rather than a modified
> > > AC_TRY_COMPILE.
> >
> > I believe that AC_TRY_COMPILE_NO_WARNING is the correct test to use
> > here.  We have already determined that the gethostbyname_r function
> > exists - we do not need to link or run a test program.  If we have
> > the wrong arguments to the function, we will receive a compiler
> > warning and we will fail the test.  I do not see what the additional
> > steps of the AC_TRY_RUN test will give us.
> >
> > You may be correct that the names are slightly misleading.  However,
> > Sterling originally intended those values to be indicative of what
> > the style was rather than how many arguments.  Personally, I don't
> > care much about names.  No one is ever happy with our names anyway.
> > Feel free to submit a patch that changes the #defines names if you
> > want.  -- justin
> >
>
>     I've actually investigated cURL's solution, it was one of the
>     bases for my research.  You don't need to use AC_TRY_RUN in this
>     case, its simple, if it compiles without warnings -- it works.  Yes,
>     there are cases where gethostbyname is broken, but there should be
>     an extra check for that -- and AC_TRY_RUN() won't pick up this error
>     anyway.


    Sorry for replying to my own message, let me just clarify this:

    curl's version of the gethostbyname_r() tries to resolve localhost
    in AC_TRY_RUN(), on some systems, localhost doesn't resolve, thus
    AC_TRY_RUN() will fail, even when the argument order is correct.
    Therefore you need an additional check, to see whether localhost
    resolvers.

>     The approach in the apr_network.m4, shows the style of the
>     arguments,not the number of arguments.  I prefer specifying style,
>     because it makes more sense to me that way ("ohh, ok, this is how its
>     done on glibc2 systems". :)
>
>     -Sterling
>
>


Re: APR_CHECK_GETHOSTBYNAME_R_STYLE (ick)

Posted by Sterling Hughes <st...@designmultimedia.com>.
On Thu, 9 Aug 2001, Justin Erenkrantz wrote:

> [ This message belongs at dev@apr.apache.org not new-httpd ]
>
> On Thu, Aug 09, 2001 at 05:46:40AM -0500, new-httpd@thewrittenword.com wrote:
> > Between Solaris, HP-UX, AIX, Tru64 UNIX, and IRIX, there are three
> > possibilities for the number of arguments to gethostbyname_r: 3, 5, 6.
> >
> > I think the test to determine the number of arguments in
> > apr_network.m4 is inadequate. The ones used by the cURL program
> > (http://curl.haxx.se) seem far more robust in that it uses AC_TRY_RUN
> > to determine the correct number of arguments rather than a modified
> > AC_TRY_COMPILE.
>
> I believe that AC_TRY_COMPILE_NO_WARNING is the correct test to use
> here.  We have already determined that the gethostbyname_r function
> exists - we do not need to link or run a test program.  If we have
> the wrong arguments to the function, we will receive a compiler
> warning and we will fail the test.  I do not see what the additional
> steps of the AC_TRY_RUN test will give us.
>
> You may be correct that the names are slightly misleading.  However,
> Sterling originally intended those values to be indicative of what
> the style was rather than how many arguments.  Personally, I don't
> care much about names.  No one is ever happy with our names anyway.
> Feel free to submit a patch that changes the #defines names if you
> want.  -- justin
>

    I've actually investigated cURL's solution, it was one of the
    bases for my research.  You don't need to use AC_TRY_RUN in this
    case, its simple, if it compiles without warnings -- it works.  Yes,
    there are cases where gethostbyname is broken, but there should be
    an extra check for that -- and AC_TRY_RUN() won't pick up this error
    anyway.  The approach in the apr_network.m4, shows the style of the
    arguments,not the number of arguments.  I prefer specifying style,
    because it makes more sense to me that way ("ohh, ok, this is how its
    done on glibc2 systems". :)

    -Sterling



Re: APR_CHECK_GETHOSTBYNAME_R_STYLE (ick)

Posted by Justin Erenkrantz <je...@ebuilt.com>.
[ This message belongs at dev@apr.apache.org not new-httpd ]

On Thu, Aug 09, 2001 at 05:46:40AM -0500, new-httpd@thewrittenword.com wrote:
> Between Solaris, HP-UX, AIX, Tru64 UNIX, and IRIX, there are three
> possibilities for the number of arguments to gethostbyname_r: 3, 5, 6.
> 
> I think the test to determine the number of arguments in
> apr_network.m4 is inadequate. The ones used by the cURL program
> (http://curl.haxx.se) seem far more robust in that it uses AC_TRY_RUN
> to determine the correct number of arguments rather than a modified
> AC_TRY_COMPILE.

I believe that AC_TRY_COMPILE_NO_WARNING is the correct test to use
here.  We have already determined that the gethostbyname_r function
exists - we do not need to link or run a test program.  If we have
the wrong arguments to the function, we will receive a compiler 
warning and we will fail the test.  I do not see what the additional
steps of the AC_TRY_RUN test will give us.

You may be correct that the names are slightly misleading.  However,
Sterling originally intended those values to be indicative of what
the style was rather than how many arguments.  Personally, I don't
care much about names.  No one is ever happy with our names anyway.
Feel free to submit a patch that changes the #defines names if you 
want.  -- justin