diff options
author | Martin Schwenke <martin@meltin.net> | 2017-06-02 16:17:22 +1000 |
---|---|---|
committer | Martin Schwenke <martins@samba.org> | 2017-09-19 13:30:26 +0200 |
commit | 22de111ebfbbb74ae0f47e4812db967747873545 (patch) | |
tree | cd7e676499d2efc934f72e065de67ff06450c03d /ctdb/protocol | |
parent | eb32b8d3a0320413db3e01019040c12aeb3f902c (diff) | |
download | samba-22de111ebfbbb74ae0f47e4812db967747873545.tar.gz |
ctdb-protocol: Add ctdb_sock_addr_port() and sock_addr_set_port()
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb/protocol')
-rw-r--r-- | ctdb/protocol/protocol_util.c | 28 | ||||
-rw-r--r-- | ctdb/protocol/protocol_util.h | 2 |
2 files changed, 30 insertions, 0 deletions
diff --git a/ctdb/protocol/protocol_util.c b/ctdb/protocol/protocol_util.c index 3b039446af3..91e8cfc7349 100644 --- a/ctdb/protocol/protocol_util.c +++ b/ctdb/protocol/protocol_util.c @@ -139,6 +139,34 @@ const char *ctdb_sock_addr_to_string(TALLOC_CTX *mem_ctx, ctdb_sock_addr *addr) return cip; } +unsigned int ctdb_sock_addr_port(ctdb_sock_addr *addr) +{ + switch (addr->sa.sa_family) { + case AF_INET: + return ntohs(addr->ip.sin_port); + break; + case AF_INET6: + return ntohs(addr->ip6.sin6_port); + break; + default: + return 0; + } +} + +void ctdb_sock_addr_set_port(ctdb_sock_addr *addr, unsigned int port) +{ + switch (addr->sa.sa_family) { + case AF_INET: + addr->ip.sin_port = htons(port); + break; + case AF_INET6: + addr->ip6.sin6_port = htons(port); + break; + default: + break; + } +} + int ctdb_sock_addr_cmp_ip(const ctdb_sock_addr *addr1, const ctdb_sock_addr *addr2) { diff --git a/ctdb/protocol/protocol_util.h b/ctdb/protocol/protocol_util.h index 94778817efd..c139891e50e 100644 --- a/ctdb/protocol/protocol_util.h +++ b/ctdb/protocol/protocol_util.h @@ -31,6 +31,8 @@ const char *ctdb_event_to_string(enum ctdb_event event); enum ctdb_event ctdb_event_from_string(const char *event_str); const char *ctdb_sock_addr_to_string(TALLOC_CTX *mem_ctx, ctdb_sock_addr *addr); +unsigned int ctdb_sock_addr_port(ctdb_sock_addr *addr); +void ctdb_sock_addr_set_port(ctdb_sock_addr *addr, unsigned int port); int ctdb_sock_addr_cmp_ip(const ctdb_sock_addr *addr1, const ctdb_sock_addr *addr2); int ctdb_sock_addr_cmp(const ctdb_sock_addr *addr1, |