[PATCH 1/2] util: fix byte order of port in virSocketAddrResolveService

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

 



The ports in the socket address structures returned by getaddrinfo() are
in network byte order. Convert to host byte order before returning them.

Signed-off-by: Michael Chapman <mike@xxxxxxxxxxxxxxxxx>
---
 src/util/virsocketaddr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c
index c1fd5ec3d2..bba2089436 100644
--- a/src/util/virsocketaddr.c
+++ b/src/util/virsocketaddr.c
@@ -265,12 +265,12 @@ int virSocketAddrResolveService(const char *service)
         if (tmp->ai_family == AF_INET) {
             struct sockaddr_in in;
             memcpy(&in, tmp->ai_addr, sizeof(in));
-            port = in.sin_port;
+            port = ntohs(in.sin_port);
             goto cleanup;
         } else if (tmp->ai_family == AF_INET6) {
             struct sockaddr_in6 in;
             memcpy(&in, tmp->ai_addr, sizeof(in));
-            port = in.sin6_port;
+            port = ntohs(in.sin6_port);
             goto cleanup;
         }
         tmp++;
-- 
2.20.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux