|
@@ -0,0 +1,424 @@
+diff --git a/configure b/configure
+index 9955bd2..8ac0177 100755
+--- a/configure
++++ b/configure
+@@ -6916,7 +6916,7 @@ fi
+
+
+ cat >>confdefs.h <<_ACEOF
+-#define DEFAULT_SERVER_PORT $nsca_port
++#define DEFAULT_SERVER_PORT "$nsca_port"
+ _ACEOF
+
+
+diff --git a/configure.in b/configure.in
+index d7beb01..24f2d9b 100644
+--- a/configure.in
++++ b/configure.in
+@@ -218,7 +218,7 @@ AC_ARG_WITH(nsca_port,--with-nsca-port=<port> sets port number for NSCA to liste
+ AC_SUBST(nsca_user)
+ AC_SUBST(nsca_grp)
+ AC_SUBST(nsca_port)
+-AC_DEFINE_UNQUOTED(DEFAULT_SERVER_PORT,$nsca_port)
++AC_DEFINE_UNQUOTED(DEFAULT_SERVER_PORT,["$nsca_port"])
+
+ AC_PATH_PROG(PERL,perl)
+ AC_OUTPUT(Makefile subst src/Makefile)
+diff --git a/include/netutils.h b/include/netutils.h
+index 21a2bcb..3aca2b1 100644
+--- a/include/netutils.h
++++ b/include/netutils.h
+@@ -31,10 +31,7 @@
+
+ #include "../include/config.h"
+
+-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 *);
+
+ int sendall(int,char *,int *);
+ int recvall(int,char *,int *,int);
+diff --git a/src/netutils.c b/src/netutils.c
+index 75ff7ca..baff11b 100644
+--- a/src/netutils.c
++++ b/src/netutils.c
+@@ -35,176 +35,55 @@
+
+
+ /* opens a connection to a remote host/tcp port */
+-int my_tcp_connect(char *host_name,int port,int *sd){
++int my_tcp_connect(char *host_name,char *port,int *sd6){
+ int result;
+-
+- result=my_connect(host_name,port,sd,"tcp");
+-
+- return result;
+- }
+-
+-
+-/* opens a tcp or udp connection to a remote host */
+-int my_connect(char *host_name,int port,int *sd,char *proto){
+- struct sockaddr_in servaddr;
+- struct hostent *hp;
+- struct protoent *ptrp;
+- int result;
+-
+- bzero((char *)&servaddr,sizeof(servaddr));
+- servaddr.sin_family=AF_INET;
+- servaddr.sin_port=htons(port);
+-
+- /* try to bypass using a DNS lookup if this is just an IP address */
+- if(!my_inet_aton(host_name,&servaddr.sin_addr)){
+-
+- /* else do a DNS lookup */
+- hp=gethostbyname((const char *)host_name);
+- if(hp==NULL){
+- printf("Invalid host name '%s'\n",host_name);
+- return STATE_UNKNOWN;
+- }
+-
+- memcpy(&servaddr.sin_addr,hp->h_addr,hp->h_length);
+- }
+-
+- /* map transport protocol name to protocol number */
+- if(((ptrp=getprotobyname(proto)))==NULL){
+- printf("Cannot map \"%s\" to protocol number\n",proto);
++ int rval;
++ int success=0;
++ struct addrinfo addrinfo;
++ struct addrinfo *res, *r;
++
++ memset(&addrinfo, 0, sizeof(addrinfo));
++ addrinfo.ai_family=PF_UNSPEC;
++ addrinfo.ai_socktype=SOCK_STREAM;
++ addrinfo.ai_protocol=IPPROTO_TCP;
++ if (rval = getaddrinfo(host_name, port, &addrinfo, &res) != 0) {
++ printf("Invalid host name '%s'\n",host_name);
+ return STATE_UNKNOWN;
+- }
+-
+- /* create a socket */
+- *sd=socket(PF_INET,(!strcmp(proto,"udp"))?SOCK_DGRAM:SOCK_STREAM,ptrp->p_proto);
+- if(*sd<0){
+- printf("Socket creation failed\n");
+- return STATE_UNKNOWN;
+- }
+-
+- /* open a connection */
+- result=connect(*sd,(struct sockaddr *)&servaddr,sizeof(servaddr));
+- if(result<0){
+- switch(errno){
+- case ECONNREFUSED:
+- printf("Connection refused by host\n");
+- break;
+- case ETIMEDOUT:
+- printf("Timeout while attempting connection\n");
+- break;
+- case ENETUNREACH:
+- printf("Network is unreachable\n");
++ }
++
++ for (r=res; r; r = r->ai_next) {
++ *sd6 = socket(r->ai_family, r->ai_socktype, r->ai_protocol);
++ result=connect(*sd6, r->ai_addr, r->ai_addrlen);
++
++ if(result<0){
++ switch(errno){
++ case ECONNREFUSED:
++ printf("Connection refused by host\n");
++ break;
++ case ETIMEDOUT:
++ printf("Timeout while attempting connection\n");
++ break;
++ case ENETUNREACH:
++ printf("Network is unreachable\n");
++ break;
++ default:
++ printf("Connection refused or timed out\n");
++ }
++ (void) close(*sd6);
++ }
++ else {
++ success++;
+ break;
+- default:
+- printf("Connection refused or timed out\n");
+- }
+-
++ }
++ }
++ if (success == 0) {
++ printf("Socket creation failed\n");
++ freeaddrinfo(res);
+ return STATE_CRITICAL;
+- }
+-
++ }
++ freeaddrinfo(res);
+ return STATE_OK;
+- }
+-
+-
+-
+-/* This code was taken from Fyodor's nmap utility, which was originally taken from
+- the GLIBC 2.0.6 libraries because Solaris doesn't contain the inet_aton() funtion. */
+-int my_inet_aton(register const char *cp, struct in_addr *addr){
+- register unsigned int val; /* changed from u_long --david */
+- register int base, n;
+- register char c;
+- u_int parts[4];
+- register u_int *pp = parts;
+-
+- c=*cp;
+-
+- for(;;){
+-
+- /*
+- * Collect number up to ``.''.
+- * Values are specified as for C:
+- * 0x=hex, 0=octal, isdigit=decimal.
+- */
+- if (!isdigit((int)c))
+- return (0);
+- val=0;
+- base=10;
+-
+- if(c=='0'){
+- c=*++cp;
+- if(c=='x'||c=='X')
+- base=16,c=*++cp;
+- else
+- base=8;
+- }
+-
+- for(;;){
+- if(isascii((int)c) && isdigit((int)c)){
+- val=(val*base)+(c -'0');
+- c=*++cp;
|