From 1ca59d89c6b7503fe065fb75d717e1487aea5b84 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Tue, 15 Mar 2016 16:35:23 +0100 Subject: [PATCH] virsocketaddr: Introduce virSocketAddrSetIPv6Addr This is a missing counterpart for virSocketAddrSetIPv4Addr() and is going to be needed later in the tests. Signed-off-by: Michal Privoznik --- src/libvirt_private.syms | 1 + src/util/virsocketaddr.c | 15 +++++++++++++++ src/util/virsocketaddr.h | 1 + 3 files changed, 17 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 3ae18b8f29..640c6b3138 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2165,6 +2165,7 @@ virSocketAddrParseIPv4; virSocketAddrParseIPv6; virSocketAddrPrefixToNetmask; virSocketAddrSetIPv4Addr; +virSocketAddrSetIPv6Addr; virSocketAddrSetPort; # util/virstats.h diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index 900aa5b783..b44d12e652 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -188,6 +188,21 @@ virSocketAddrSetIPv4Addr(virSocketAddrPtr addr, uint32_t val) addr->len = sizeof(struct sockaddr_in); } +/* + * virSocketAddrSetIPv6Addr: + * @addr: the location to store the result + * @val: the 128bit integer in host byte order representing the IPv6 address + * + * Set the IPv6 address given an integer in host order. This function does not + * touch any previously set port. + */ +void virSocketAddrSetIPv6Addr(virSocketAddrPtr addr, uint32_t val[4]) +{ + addr->data.stor.ss_family = AF_INET6; + memcpy(addr->data.inet6.sin6_addr.s6_addr, val, 4 * sizeof(*val)); + addr->len = sizeof(struct sockaddr_in6); +} + /* * virSocketAddrEqual: * @s1: the location of the one IP address diff --git a/src/util/virsocketaddr.h b/src/util/virsocketaddr.h index 9e2680a4d2..9a6e1ecfa0 100644 --- a/src/util/virsocketaddr.h +++ b/src/util/virsocketaddr.h @@ -85,6 +85,7 @@ int virSocketAddrParseIPv6(virSocketAddrPtr addr, const char *val); void virSocketAddrSetIPv4Addr(virSocketAddrPtr s, uint32_t addr); +void virSocketAddrSetIPv6Addr(virSocketAddrPtr s, uint32_t addr[4]); char *virSocketAddrFormat(const virSocketAddr *addr); char *virSocketAddrFormatFull(const virSocketAddr *addr, -- GitLab