util: Add virSocketAddrSetIPv[46]AddrNetOrder and use it

This allows setting the address in host and/or network order and makes
the naming consistent.  Now you don't need to call [hn]to[nh]l()
functions as that is taken care of by these functions.  Also, now
the *NetOrder take the address in network order, the other functions in
host order so the naming and usage is consistent.  Some places were
having the address in network order and calling ntohl() just so the
original function can call htonl() again.  This makes it nicer to read.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Martin Kletzander
2016-03-21 11:28:33 +01:00
parent 6d28ef912c
commit 573c41a275
5 changed files with 48 additions and 12 deletions
+3 -4
View File
@@ -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);
}
if (!(ipAddr = virSocketAddrFormat(&sa))) {