]> xenbits.xensource.com Git - libvirt.git/commitdiff
Properly convert port numbers to/from network byte order
authorMatthew Booth <mbooth@redhat.com>
Thu, 5 Nov 2009 16:56:08 +0000 (17:56 +0100)
committerDaniel Veillard <veillard@redhat.com>
Thu, 5 Nov 2009 16:56:08 +0000 (17:56 +0100)
* src/util/network.c: Add htons and ntohs in virSocket(Get|Set)Port

src/util/network.c

index d67340a6f5f35e4ac4fcf64e4d1b7201d7421d5a..56426e712fea080a4b2a3cb710a7e75c1d53ba08 100644 (file)
@@ -173,6 +173,8 @@ virSocketSetPort(virSocketAddrPtr addr, int port) {
     if (addr == NULL)
         return -1;
 
+    port = htons(port);
+
     if(addr->stor.ss_family == AF_INET) {
         addr->inet4.sin_port = port;
     }
@@ -201,11 +203,11 @@ virSocketGetPort(virSocketAddrPtr addr) {
         return -1;
 
     if(addr->stor.ss_family == AF_INET) {
-        return addr->inet4.sin_port;
+        return ntohs(addr->inet4.sin_port);
     }
 
     else if(addr->stor.ss_family == AF_INET6) {
-        return addr->inet6.sin6_port;
+        return ntohs(addr->inet6.sin6_port);
     }
 
     return -1;