summaryrefslogtreecommitdiff
path: root/ctdb/protocol/protocol_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'ctdb/protocol/protocol_util.c')
-rw-r--r--ctdb/protocol/protocol_util.c46
1 files changed, 34 insertions, 12 deletions
diff --git a/ctdb/protocol/protocol_util.c b/ctdb/protocol/protocol_util.c
index 91e8cfc7349..d8ee62da424 100644
--- a/ctdb/protocol/protocol_util.c
+++ b/ctdb/protocol/protocol_util.c
@@ -111,31 +111,53 @@ enum ctdb_event ctdb_event_from_string(const char *event_str)
return CTDB_EVENT_MAX;
}
-const char *ctdb_sock_addr_to_string(TALLOC_CTX *mem_ctx, ctdb_sock_addr *addr)
+int ctdb_sock_addr_to_buf(char *buf, socklen_t buflen, ctdb_sock_addr *addr)
{
- char *cip;
-
- cip = talloc_size(mem_ctx, 128);
- if (cip == NULL) {
- return "Memory Error";
- }
+ const char *t;
switch (addr->sa.sa_family) {
case AF_INET:
- inet_ntop(addr->ip.sin_family, &addr->ip.sin_addr,
- cip, 128);
+ t = inet_ntop(addr->ip.sin_family, &addr->ip.sin_addr,
+ buf, buflen);
+ if (t == NULL) {
+ return errno;
+ }
break;
case AF_INET6:
- inet_ntop(addr->ip6.sin6_family, &addr->ip6.sin6_addr,
- cip, 128);
+ t = inet_ntop(addr->ip6.sin6_family, &addr->ip6.sin6_addr,
+ buf, buflen);
+ if (t == NULL) {
+ return errno;
+ }
break;
default:
- sprintf(cip, "Unknown family %u", addr->sa.sa_family);
+ return EAFNOSUPPORT;
break;
}
+ return 0;
+}
+
+const char *ctdb_sock_addr_to_string(TALLOC_CTX *mem_ctx, ctdb_sock_addr *addr)
+{
+ size_t len = 64;
+ char *cip;
+ int ret;
+
+ cip = talloc_size(mem_ctx, len);
+
+ if (cip == NULL) {
+ return NULL;
+ }
+
+ ret = ctdb_sock_addr_to_buf(cip, len, addr);
+ if (ret != 0) {
+ talloc_free(cip);
+ return NULL;
+ }
+
return cip;
}