diff options
author | Matt Stancliff <matt@genges.com> | 2014-10-23 12:40:02 -0400 |
---|---|---|
committer | Matt Stancliff <matt@genges.com> | 2014-12-11 10:05:35 -0500 |
commit | 2d90619f88b81d1a094a875d73f8afd244480730 (patch) | |
tree | 7b5058186f2aac666a73018327dbf95d2feb0c10 /src/sds.c | |
parent | 3cd36a4dd9b31b351c87f1084bc6166a44044315 (diff) | |
download | redis-2d90619f88b81d1a094a875d73f8afd244480730.tar.gz |
Add centralized IP/Peer formatting functions
This stops us from needing to manually check against ":" to
add brackets around IPv6 addresses everywhere.
Diffstat (limited to 'src/sds.c')
-rw-r--r-- | src/sds.c | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -962,6 +962,15 @@ sds sdsjoin(char **argv, int argc, char *sep) { return join; } +sds sdsformatip(char *ip, int port) { + if (port >= 0) + return sdscatfmt(sdsempty(), + strchr(ip,':') ? "[%s]:%i" : "%s:%i", ip, port); + else + return sdscatfmt(sdsempty(), + strchr(ip,':') ? "[%s]" : "%s", ip); +} + #ifdef SDS_TEST_MAIN #include <stdio.h> #include "testhelp.h" |