[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] build: avoid non-portable IPv6 struct member, for MacOS X



* src/util/network.c (getIPv6Addr): Manually join s6_addr bytes,
instead of assuming s6_addr16 shorts.
Reported by Justin Clifton; solution suggested by Bruno Haible.
---

Like this.  Tested on Fedora, not MacOS X; but since getting it wrong
_does_ fail the testsuite, I'm confident it works (spoken as one who
swapped the in6_addr[2*i] and in6_addr[2*i+1] bytes on my first attempt).

 src/util/network.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/src/util/network.c b/src/util/network.c
index b17d419..17aa746 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -47,7 +47,8 @@ static int getIPv6Addr(virSocketAddrPtr addr, virIPv6AddrPtr tab) {
         return(-1);

     for (i = 0;i < 8;i++) {
-        (*tab)[i] = ntohs(addr->inet6.sin6_addr.s6_addr16[i]);
+        (*tab)[i] = ((addr->inet6.sin6_addr.s6_addr[2 * i] << 8) |
+                     addr->inet6.sin6_addr.s6_addr[2 * i + 1]);
     }

     return(0);
-- 
1.7.2.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]