Incredible as it may seem, given the success of the Web, there is no easy way
for a program to find the port of the HTTP service (except hardcoding 80...).
All Free Unices declare 'http' and 'www' in /etc/services, but AIX declares
only 'www' (which is not a protocol name) and Solaris declares nothing :-(
I need to be able to:
if ((sp = getservbyname (HTTP_PORT, "tcp")) == NULL)
and I currently use the following, which is far from perfect. SUggestions are
welcome:
dnl Check the port name for HTTP. Everyone should declare "http" but
dnl not everyone does. this test is not perfect, we should use a program
dnl which calls getservbyname() otherwise we miss NIS tables, for
dnl instance.
AC_DEFUN([CF_CHECK_SERVICES],
[
AC_MSG_CHECKING(what is the name of the HTTP port in your services database)
dnl We should test it is really port 80 and not any mention of "http"
if grep http /etc/services > /dev/null; then
AC_DEFINE(HTTP_TCP_PORT,"http")
AC_MSG_RESULT(http)
else
dnl Trap on Solaris with a port whose name begins with "www" but is no
80...
if grep www /etc/services > /dev/null; then
AC_DEFINE(HTTP_TCP_PORT,"www")
AC_MSG_RESULT(www)
else
AC_DEFINE(HTTP_TCP_PORT,"undefined:use_:80")
AC_MSG_RESULT([undefined, you should add it in your database])
fi
fi
I planned to use a program calling getservbyname but I have the issue of
cross-compiling. My first try:
AC_DEFUN([CF_CHECK_TCP_SERVICE],
[
AC_TRY_RUN([
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
int
main (argc, argv)
int argc;
char *argv[];
{
struct servent *sp;
if ((sp = getservbyname ("$1", "tcp")) == 0)
exit (1);
else
exit (0);
}
],
ac_last_port=$1
,
ac_last_port=
)])