]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: fix byte order of port in virSocketAddrResolveService
authorMichael Chapman <mike@very.puzzling.org>
Tue, 17 Sep 2019 07:03:56 +0000 (17:03 +1000)
committerDaniel P. Berrangé <berrange@redhat.com>
Tue, 17 Sep 2019 09:35:50 +0000 (10:35 +0100)
The ports in the socket address structures returned by getaddrinfo() are
in network byte order. Convert to host byte order before returning them.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Michael Chapman <mike@very.puzzling.org>
src/util/virsocketaddr.c

index c1fd5ec3d2925fdd73ed75c8d3900d93055dd47c..bba2089436f510189b4148f41632b198f7a0159d 100644 (file)
@@ -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++;