Sfoglia il codice sorgente

totemip: Add totemip_sa_print function

Backport part of 69857efb5b24dc2473acc6e7653e5e41886ad03d.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
Jan Friesse 6 anni fa
parent
commit
9a2e5a240b
2 ha cambiato i file con 23 aggiunte e 0 eliminazioni
  1. 22 0
      exec/totemip.c
  2. 1 0
      include/corosync/totem/totemip.h

+ 22 - 0
exec/totemip.c

@@ -211,6 +211,28 @@ int totemip_localhost_check(const struct totem_ip_address *addr)
 	return totemip_equal(addr, &localhost);
 }
 
+const char *totemip_sa_print(const struct sockaddr *sa)
+{
+	static char buf[INET6_ADDRSTRLEN];
+
+	buf[0] = 0;
+
+	switch (sa->sa_family) {
+	case AF_INET:
+		inet_ntop(sa->sa_family, &((struct sockaddr_in *)(sa))->sin_addr, buf,
+		    INET6_ADDRSTRLEN);
+		break;
+	case AF_INET6:
+		inet_ntop(sa->sa_family, &((struct sockaddr_in6 *)(sa))->sin6_addr, buf,
+		    INET6_ADDRSTRLEN);
+		break;
+	default:
+		return (NULL);
+	}
+
+	return (buf);
+}
+
 const char *totemip_print(const struct totem_ip_address *addr)
 {
 	static char buf[INET6_ADDRSTRLEN];

+ 1 - 0
include/corosync/totem/totemip.h

@@ -88,6 +88,7 @@ extern void totemip_copy_endian_convert(struct totem_ip_address *addr1,
 int totemip_localhost(int family, struct totem_ip_address *localhost);
 extern int totemip_localhost_check(const struct totem_ip_address *addr);
 extern const char *totemip_print(const struct totem_ip_address *addr);
+extern const char *totemip_sa_print(const struct sockaddr *sa);
 extern int totemip_sockaddr_to_totemip_convert(const struct sockaddr_storage *saddr,
 					       struct totem_ip_address *ip_addr);
 extern int totemip_totemip_to_sockaddr_convert(struct totem_ip_address *ip_addr,