mirror of
https://github.com/libvirt/libvirt.git
synced 2026-08-09 12:38:27 -05:00
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:
+3
-4
@@ -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))) {
|
||||
|
||||
Reference in New Issue
Block a user