Преглед изворни кода

Fix debug display of remote port

Doug Nazar пре 1 година
родитељ
комит
4083cff8fc
1 измењених фајлова са 6 додато и 5 уклоњено
  1. 6 5
      src/nrpe.c

+ 6 - 5
src/nrpe.c

@@ -1407,6 +1407,7 @@ void conn_check_peer(int sock)
 
 
 	char      ipstr[INET6_ADDRSTRLEN];
 	char      ipstr[INET6_ADDRSTRLEN];
 	socklen_t addrlen;
 	socklen_t addrlen;
+	int       remote_port = 0;
 	int       rc;
 	int       rc;
 
 
 	/* find out who just connected... */
 	/* find out who just connected... */
@@ -1433,6 +1434,7 @@ void conn_check_peer(int sock)
 		nptr = (struct sockaddr_in *)&addr;
 		nptr = (struct sockaddr_in *)&addr;
 		strncpy(remote_host, inet_ntoa(nptr->sin_addr), sizeof(remote_host) - 1);
 		strncpy(remote_host, inet_ntoa(nptr->sin_addr), sizeof(remote_host) - 1);
 		remote_host[MAX_HOST_ADDRESS_LENGTH - 1] = '\0';
 		remote_host[MAX_HOST_ADDRESS_LENGTH - 1] = '\0';
+		remote_port = ntohs(nptr->sin_port);
 		break;
 		break;
 
 
 	case AF_INET6:
 	case AF_INET6:
@@ -1443,12 +1445,13 @@ void conn_check_peer(int sock)
 		}
 		}
 		strncpy(remote_host, ipstr, sizeof(remote_host) - 1);
 		strncpy(remote_host, ipstr, sizeof(remote_host) - 1);
 		remote_host[MAX_HOST_ADDRESS_LENGTH - 1] = '\0';
 		remote_host[MAX_HOST_ADDRESS_LENGTH - 1] = '\0';
+		remote_port = ntohs(nptr6->sin6_port);
 		break;
 		break;
 	}
 	}
 
 
 	if (debug == TRUE)
 	if (debug == TRUE)
 		logit(LOG_INFO, "CONN_CHECK_PEER: checking if host is allowed: %s port %d\n",
 		logit(LOG_INFO, "CONN_CHECK_PEER: checking if host is allowed: %s port %d\n",
-			 remote_host, nptr->sin_port);
+			 remote_host, remote_port);
 
 
 	/* is this host allowed? */
 	/* is this host allowed? */
 	if (allowed_hosts) {
 	if (allowed_hosts) {
@@ -1461,7 +1464,7 @@ void conn_check_peer(int sock)
 		case AF_INET:
 		case AF_INET:
 			/* log info */
 			/* log info */
 			if (debug == TRUE || (sslprm.log_opts & SSL_LogIpAddr))
 			if (debug == TRUE || (sslprm.log_opts & SSL_LogIpAddr))
-				logit(LOG_DEBUG, "Connection from %s port %d", remote_host, nptr->sin_port);
+				logit(LOG_DEBUG, "Connection from %s port %d", remote_host, remote_port);
 
 
 			if (!is_an_allowed_host(AF_INET, (void *)&(nptr->sin_addr))) {
 			if (!is_an_allowed_host(AF_INET, (void *)&(nptr->sin_addr))) {
 				/* log error */
 				/* log error */
@@ -1487,10 +1490,8 @@ void conn_check_peer(int sock)
 
 
 		case AF_INET6:
 		case AF_INET6:
 			/* log info */
 			/* log info */
-			strncpy(remote_host, ipstr, sizeof(remote_host));
-			remote_host[sizeof(remote_host) - 1] = '\0';
 			if (debug == TRUE || (sslprm.log_opts & SSL_LogIpAddr)) {
 			if (debug == TRUE || (sslprm.log_opts & SSL_LogIpAddr)) {
-				logit(LOG_DEBUG, "Connection from %s port %d", ipstr, nptr6->sin6_port);
+				logit(LOG_DEBUG, "Connection from %s port %d", remote_host, remote_port);
 			}
 			}
 
 
 			if (!is_an_allowed_host(AF_INET6, (void *)&(nptr6->sin6_addr))) {
 			if (!is_an_allowed_host(AF_INET6, (void *)&(nptr6->sin6_addr))) {