Skip to contentSkip to conversation

Print client port

PATCH In review Pete Zaitcev 2 participants 2 messages May 21, 2010 – May 25, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 4/6 Print client port

The originating port is interesting when the same client contacts the chunkserver several times and we, for example, look at that with tcpdump.

---
 server/chunkd.h |    1 +
 server/server.c |   11 ++++++++---
 2 files changed, 9 insertions(+), 3 deletions(-)

commit 7e2cc1ad8b1de3e33402147841d794e13b4f65f9

Author: Master <[email protected]>
Date:   Thu May 20 21:32:43 2010 -0600

Print port too (to match against tcpdump, for example).

server/chunkd.h +1 -0
index e5721cd..47e6f95 100644
@@ -84,6 +84,7 @@ struct client {
 
 	struct sockaddr_in6	addr;		/* inet address */
 	char			addr_host[64];	/* ASCII version of inet addr */
+	char			addr_port[16];	/* ASCII version of port */
 	int			fd;		/* socket */
 
 	char			user[CHD_USER_SZ + 1];
server/server.c +8 -3
index de9e6a8..2d2f6c3 100644
@@ -343,7 +343,8 @@ static void cli_write_free_all(struct client *cli)
 
 static void cli_free(struct client *cli)
 {
-	applog(LOG_INFO, "client %s disconnected", cli->addr_host);
+	applog(LOG_INFO, "client host %s port %s disconnected",
+	       cli->addr_host, cli->addr_port);
 
 	cli_write_free_all(cli);
 
@@ -1341,6 +1342,7 @@ static bool tcp_srv_event(int fd, short events, void *userdata)
 	socklen_t addrlen = sizeof(struct sockaddr_in6);
 	struct client *cli;
 	char host[64];
+	char port[16];
 	int on = 1;
 	struct server_poll *sp;
 
@@ -1381,13 +1383,16 @@ static bool tcp_srv_event(int fd, short events, void *userdata)
 
 	/* pretty-print incoming cxn info */
 	memset(host, 0, sizeof(host));
+	memset(port, 0, sizeof(port));
 	getnameinfo((struct sockaddr *) &cli->addr, addrlen,
-		    host, sizeof(host), NULL, 0, NI_NUMERICHOST);
+		    host, sizeof(host), port, sizeof(port), NI_NUMERICHOST);
 	host[sizeof(host) - 1] = 0;
-	applog(LOG_INFO, "client %s connected%s", host,
+	host[sizeof(port) - 1] = 0;
+	applog(LOG_INFO, "client host %s port %s connected%s", host, port,
 		cli->ssl ? " via SSL" : "");
 
 	strcpy(cli->addr_host, host);
+	strcpy(cli->addr_port, port);
 
 	if (!srv_poll_ready(fd))
 		applog(LOG_ERR, "unable to ready srv fd for polling");
#1 lore raw

server/server.c static bool tcp_srv_event(int fd, short events, void *userdata) · line 1390

Quoted 5 lines · Pete Zaitcev
server/server.c +2 -2
-		    host, sizeof(host), NULL, 0, NI_NUMERICHOST);
+		    host, sizeof(host), port, sizeof(port), NI_NUMERICHOST);
  	host[sizeof(host) - 1] = 0;
-	applog(LOG_INFO, "client %s connected%s", host,
+	host[sizeof(port) - 1] = 0;

You truncate the wrong variable.