On Fri, Mar 18, 2016 at 17:42:28 +0100, Martin Kletzander wrote: > This allows setting the address if you already have the address in > network byte order. Some places were having the address in network > order and calling ntohl() just so the original function can call htonl() > again. Let's call the new one to make clear what's happening. > > Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx> > --- > src/libvirt_private.syms | 2 ++ > src/nwfilter/nwfilter_dhcpsnoop.c | 4 ++-- > src/util/virsocketaddr.c | 45 +++++++++++++++++++++++++++++++++------ > src/util/virsocketaddr.h | 2 ++ > tests/nsstest.c | 7 +++--- > 5 files changed, 48 insertions(+), 12 deletions(-) > [...] > diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c > index b44d12e65216..53a8af898ead 100644 > --- a/src/util/virsocketaddr.c > +++ b/src/util/virsocketaddr.c > @@ -173,6 +173,22 @@ virSocketAddrParseIPv6(virSocketAddrPtr addr, const char *val) > } > > /* > + * virSocketAddrSetIPv4AddrNetOrder: > + * @addr: the location to store the result > + * @val: the 128bit integer in network byte order representing the IPv4 address 32 bit, for IPv4 > + * > + * Set the IPv4 address given an integer in network order. This function does not > + * touch any previously set port. [...] > @@ -198,9 +227,13 @@ virSocketAddrSetIPv4Addr(virSocketAddrPtr addr, uint32_t val) > */ > 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); > + size_t i = 0; > + uint32_t host_val[4]; > + > + for (i = 0; i < 4; i++) > + host_val[i] = htonl(val[i]); So the docs for this function were incorrect. It was indeed setting it in the network order. You should mention this change in the commit message. [...] > diff --git a/tests/nsstest.c b/tests/nsstest.c > index 340f313616c5..68f1c600f6ec 100644 > --- a/tests/nsstest.c > +++ b/tests/nsstest.c > @@ -126,15 +126,14 @@ testGetHostByName(const void *opaque) > while (*addrList) { > virSocketAddr sa; > char *ipAddr; > + void *address = *addrList; > > memset(&sa, 0, sizeof(sa)); > > if (resolved.h_addrtype == AF_INET) { > - /* For some reason, virSocketAddrSetIPv4Addr does htonl() conversion. > - * But the data we already have is in network order. */ > - virSocketAddrSetIPv4Addr(&sa, ntohl(*((uint32_t *) *addrList))); > + virSocketAddrSetIPv4AddrNetOrder(&sa, *((uint32_t *) address)); > } else { > - virSocketAddrSetIPv6Addr(&sa, (uint32_t *) *addrList); > + virSocketAddrSetIPv6AddrNetOrder(&sa, address); Okay, this was the only place that is using the function fortunately. ACK with the two requested touch-ups. Peter
Attachment:
signature.asc
Description: Digital signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list