summaryrefslogtreecommitdiff
path: root/src/sds.c
diff options
context:
space:
mode:
authorMatt Stancliff <matt@genges.com>2014-10-23 12:40:02 -0400
committerMatt Stancliff <matt@genges.com>2014-12-11 10:05:35 -0500
commit2d90619f88b81d1a094a875d73f8afd244480730 (patch)
tree7b5058186f2aac666a73018327dbf95d2feb0c10 /src/sds.c
parent3cd36a4dd9b31b351c87f1084bc6166a44044315 (diff)
downloadredis-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.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/sds.c b/src/sds.c
index 1df1043ed..fa71896ef 100644
--- a/src/sds.c
+++ b/src/sds.c
@@ -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"