@@ -0,0 +1,701 @@
+diff --git a/configure b/configure
+index 40c5730..d18cc51 100755
+--- a/configure
++++ b/configure
+@@ -7224,7 +7224,7 @@ NRPE_INSTALL_OPTS="-o $nrpe_user -g $nrpe_group"
+
+
+ cat >>confdefs.h <<_ACEOF
+-#define DEFAULT_SERVER_PORT $nrpe_port
++#define DEFAULT_SERVER_PORT "$nrpe_port"
+ _ACEOF
+
+
+diff --git a/configure.in b/configure.in
+index b3db2cf..0d3043c 100644
+--- a/configure.in
++++ b/configure.in
+@@ -352,7 +352,7 @@ AC_SUBST(nrpe_group)
+ NRPE_INSTALL_OPTS="-o $nrpe_user -g $nrpe_group"
+ AC_SUBST(NRPE_INSTALL_OPTS)
+ AC_SUBST(nrpe_port)
+-AC_DEFINE_UNQUOTED(DEFAULT_SERVER_PORT,$nrpe_port)
++AC_DEFINE_UNQUOTED(DEFAULT_SERVER_PORT,["$nrpe_port"])
+
+ AC_ARG_WITH(icinga_user,--with-icinga-user=<user> sets user name for file permissions,icinga_user=$withval,icinga_user=icinga)
+ AC_ARG_WITH(icinga_group,--with-icinga-group=<grp> sets group name file permissions,icinga_group=$withval,icinga_group=icinga)
+diff --git a/include/nrpe.h b/include/nrpe.h
+index bb4a383..4d6c574 100644
+--- a/include/nrpe.h
++++ b/include/nrpe.h
+@@ -47,7 +47,7 @@ int write_pid_file(void);
+ int remove_pid_file(void);
+
+ void free_memory(void);
+-int is_an_allowed_host(char *);
++int is_an_allowed_host(const struct sockaddr *);
+ int validate_request(packet *);
+ int contains_nasty_metachars(char *);
+ int process_macros(char *,char *,int);
+@@ -57,5 +57,3 @@ void my_connection_sighandler(int); /* handles timeouts of connection */
+
+ void sighandler(int);
+ void child_sighandler(int);
+-
+-
+diff --git a/include/utils.h b/include/utils.h
+index 7666f38..2c6b1a5 100644
+--- a/include/utils.h
++++ b/include/utils.h
+@@ -40,10 +40,7 @@ unsigned long calculate_crc32(char *, int);
+
+ void randomize_buffer(char *,int);
+
+-int my_tcp_connect(char *,int,int *);
+-int my_connect(char *,int,int *,char *);
+-
+-int my_inet_aton(register const char *,struct in_addr *);
++int my_tcp_connect(char *,char *,int *);
+
+ void strip(char *);
+
+@@ -54,9 +51,7 @@ char *my_strsep(char **,const char *);
+
+ void display_license(void);
+
++char *get_ip_str(const struct sockaddr *, char *, size_t);
++int get_port(const struct sockaddr *);
++int sockaddr_equal(const struct sockaddr *, const struct sockaddr *);
+ #endif
+-
+-
+-
+-
+-
+diff --git a/src/check_nrpe.c b/src/check_nrpe.c
+index 47e4eea..c4e5fe8 100644
+--- a/src/check_nrpe.c
++++ b/src/check_nrpe.c
+@@ -24,7 +24,7 @@
+
+ #define DEFAULT_NRPE_COMMAND "_NRPE_CHECK" /* check version of NRPE daemon */
+
+-int server_port=DEFAULT_SERVER_PORT;
++char *server_port=DEFAULT_SERVER_PORT;
+ char *server_name=NULL;
+ char *command_name=NULL;
+ int socket_timeout=DEFAULT_SOCKET_TIMEOUT;
+@@ -366,9 +366,7 @@ int process_arguments(int argc, char **argv){
+ return ERROR;
+ break;
+ case 'p':
+- server_port=atoi(optarg);
+- if(server_port<=0)
+- return ERROR;
++ server_port=strdup(optarg);
+ break;
+ case 'H':
+ server_name=strdup(optarg);
+diff --git a/src/nrpe.c b/src/nrpe.c
+index 4a4adbb..22d2efc 100644
+--- a/src/nrpe.c
++++ b/src/nrpe.c
+@@ -44,13 +44,17 @@ int use_ssl=FALSE;
+ #define MAXFD 64
+ #define NASTY_METACHARS "|`&><'\"\\[]{};"
+
++#define BUFLEN 16384
++char buf[BUFLEN];
++
+ char *command_name=NULL;
+ char *macro_argv[MAX_COMMAND_ARGUMENTS];
+
+ char config_file[MAX_INPUT_BUFFER]="nrpe.cfg";
+ int log_facility=LOG_DAEMON;
+-int server_port=DEFAULT_SERVER_PORT;
+-char server_address[16]="0.0.0.0";
++
++char *server_port=DEFAULT_SERVER_PORT;
++char *server_address=NULL;
+ int socket_timeout=DEFAULT_SOCKET_TIMEOUT;
+ int command_timeout=DEFAULT_COMMAND_TIMEOUT;
+ int connection_timeout=DEFAULT_CONNECTION_TIMEOUT;
+@@ -435,19 +439,14 @@ int read_config_file(char *filename){
+ syslog(LOG_ERR,"Continuing with errors...");
+ }
+
+- else if(!strcmp(varname,"server_port")){
+- server_port=atoi(varvalue);
+- if(server_port<1024){
+- syslog(LOG_ERR,"Invalid port number specified in config file '%s' - Line %d\n",filename,line);
+- return ERROR;
+- }
+- }
++ else if(!strcmp(varname,"server_port"))
++ server_port=strdup(varvalue);
++
+ else if(!strcmp(varname,"command_prefix"))
+ command_prefix=strdup(varvalue);
+
+ else if(!strcmp(varname,"server_address")){
+- strncpy(server_address,varvalue,sizeof(server_address) - 1);
+- server_address[sizeof(server_address)-1]='\0';
++ server_address=strdup(varvalue);
+ }
+
+ else if(!strcmp(varname,"allowed_hosts"))
+@@ -700,12 +699,12 @@ command *find_command(char *command_name){
+
+ /* wait for incoming connection requests */
+ void wait_for_connections(void){
+- struct sockaddr_in myname;
+- struct sockaddr_in *nptr;
+- struct sockaddr addr;
++ struct sockaddr_in6 myname6;
++ struct sockaddr_in6 src_sin;
++ socklen_t socklen = sizeof(src_sin);
++ struct sockaddr *remoteaddr = (struct sockaddr *)&src_sin;
+ int rc;
+ int sock, new_sd;
+- socklen_t addrlen;
+ pid_t pid;
+ int flag=1;
+ fd_set fdread;
+@@ -715,43 +714,49 @@ void wait_for_connections(void){
+ struct request_info req;
+ #endif
+
+- /* create a socket for listening */
+- sock=socket(AF_INET,SOCK_STREAM,0);
++ int rval;
++ int success=0;
++ struct addrinfo addrinfo;
++ struct addrinfo *res, *r;
+
+- /* exit if we couldn't create the socket */
+- if(sock<0){
+- syslog(LOG_ERR,"Network server socket failure (%d: %s)",errno,strerror(errno));
+- exit(STATE_CRITICAL);
+- }
++ memset(&addrinfo, 0, sizeof(addrinfo));
++ addrinfo.ai_family=PF_UNSPEC;
++ addrinfo.ai_socktype=SOCK_STREAM;
++ addrinfo.ai_protocol=IPPROTO_TCP;
+
+- /* socket should be non-blocking */
+- fcntl(sock,F_SETFL,O_NONBLOCK);
+-
+- /* set the reuse address flag so we don't get errors when restarting */
+- flag=1;
+- if(setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,(char *)&flag,sizeof(flag))<0){
+- syslog(LOG_ERR,"Could not set reuse address option on socket!\n");
+- exit(STATE_UNKNOWN);
+- }
+-
+- myname.sin_family=AF_INET;
+- myname.sin_port=htons(server_port);
+- bzero(&myname.sin_zero,8);
+-
+- /* what address should we bind to? */
|