--- monit-2.5.orig/p.y Fri Jul 12 10:14:35 2002 +++ monit-2.5.dev/p.y Wed Jul 17 14:04:42 2002 @@ -40,6 +40,7 @@ #include #include #include +#include #include "net.h" #include "monitor.h" @@ -117,6 +118,7 @@ static void check_timeout(int, int); static void check_every (int); static void check_hostname (char *); + int string_to_port(char *service); %} @@ -234,6 +236,10 @@ Run.dohttpd= TRUE; Run.httpdport= $4; } + | SET HTTPD PORT STRING bindaddress allowlist { + Run.dohttpd= TRUE; + Run.httpdport= string_to_port($4); + } ; @@ -276,7 +282,8 @@ | HOST STRING { check_hostname($2); portset.hostname= $2; } ; -port : PORT NUMBER { portset.port= $2; } +port : PORT STRING { portset.port= string_to_port($2); } + | PORT NUMBER { portset.port= $2; } ; type : /* EMPTY */ { portset.type= SOCK_STREAM; } @@ -826,6 +833,41 @@ } +/* + * Convert a string containing a service/alias from /etc/services + * to the specific port number + */ +int string_to_port(char *service) { + + int port = 0; + struct servent * service_st = NULL; + + service_st = getservbyname(service, NULL); + + if ( service_st != NULL ) { + + port = service_st->s_port; + + if ( Run.debug ) { + + log("resolved service %s as %s/%i", service, + service_st->s_name, service_st->s_port); + + } + + free(service_st); + + } else { + + error("%s: unknow service '%s' at line %d\n", + prog, service, lineno ); + + cfg_errflag++; + + } + + return port; +} --- monit-2.5.orig/configure.in Thu Jul 11 11:49:05 2002 +++ monit-2.5.dev/configure.in Wed Jul 17 11:27:37 2002 @@ -48,6 +48,9 @@ AC_MSG_RESULT(using libc's inet_aton), AC_CHECK_LIB(resolv,inet_aton)) +AC_CHECK_FUNC(getservbyname,, + AC_CHECK_LIB(socket,getservbyname)) + AC_CHECK_LIB(pthread, pthread_create,, AC_CHECK_LIB(pthreads, pthread_create,,))