X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/9b1d738f9609b5a1865b74bdb2e2a1d49c67c9b5..4763ecc9add311467c9c3852a81664a0b3005919:/src/anet.c diff --git a/src/anet.c b/src/anet.c index 4e16f2e4..692cef19 100644 --- a/src/anet.c +++ b/src/anet.c @@ -345,3 +345,13 @@ int anetUnixAccept(char *err, int s) { return fd; } + +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 (ip) strcpy(ip,inet_ntoa(sa.sin_addr)); + if (port) *port = ntohs(sa.sin_port); + return 0; +}