From 7b845b62285230d9015f80a6c2ea7ecb0b25df6e Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 7 Mar 2012 11:30:30 +0100 Subject: [PATCH] anetPeerToString() automatically populates ip/port with something that may be provided to the user as output in case of errors. --- src/anet.c | 7 ++++++- src/networking.c | 6 +----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/anet.c b/src/anet.c index 9aff4dfa..ba4e6cce 100644 --- a/src/anet.c +++ b/src/anet.c @@ -353,7 +353,12 @@ int anetPeerToString(int fd, char *ip, int *port) { struct sockaddr_in sa; socklen_t salen = sizeof(sa); - if (getpeername(fd,(struct sockaddr*)&sa,&salen) == -1) return -1; + if (getpeername(fd,(struct sockaddr*)&sa,&salen) == -1) { + *port = 0; + ip[0] = '?'; + ip[1] = '\0'; + return -1; + } if (ip) strcpy(ip,inet_ntoa(sa.sin_addr)); if (port) *port = ntohs(sa.sin_port); return 0; diff --git a/src/networking.c b/src/networking.c index d8fb8132..40aad836 100644 --- a/src/networking.c +++ b/src/networking.c @@ -1087,11 +1087,7 @@ sds getClientInfoString(redisClient *client) { time_t now = time(NULL); int emask; - if (anetPeerToString(client->fd,ip,&port) == -1) { - ip[0] = '?'; - ip[1] = '\0'; - port = 0; - } + anetPeerToString(client->fd,ip,&port); p = flags; if (client->flags & REDIS_SLAVE) { if (client->flags & REDIS_MONITOR) -- 2.47.2