]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Use VG_(ntohl) and VG_(ntohs) to decode IP addresses and ports. Note
authorTom Hughes <tom@compton.nu>
Thu, 17 Nov 2005 12:02:58 +0000 (12:02 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 17 Nov 2005 12:02:58 +0000 (12:02 +0000)
that this also required reversing the order of the arguments to the
print call as the previous ordering assumed that the address was still
byte swapped.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@5163

coregrind/m_syswrap/syswrap-generic.c

index 351f90b99c843cd3c8aee56e15f34d7ed6cc02d9..8fc16c0f18d6bf84a84860946605df1241e98839 100644 (file)
@@ -536,20 +536,14 @@ Char *inet2name(struct vki_sockaddr_in *sa, UInt len, Char *name)
    if (sa == NULL || len == 0) {
       VG_(sprintf)(name, "<unknown>");
    } else {
-      UInt addr = sa->sin_addr.s_addr;
-#     if defined(VG_BIGENDIAN)
-      /* This is a hack.  I don't know enough to navigate my way through the
-         ntohl/ntonl maze.  JRS 17 Nov 05. */
-      addr = (((addr >> 24) & 0xFF) << 0) | (((addr >> 16) & 0xFF) << 8)
-             | (((addr >> 8) & 0xFF) << 16) | (((addr >> 0) & 0xFF) << 24);
-#     endif
+      UInt addr = VG_(ntohl)(sa->sin_addr.s_addr);
       if (addr == 0) {
          VG_(sprintf)(name, "<unbound>");
       } else {
          VG_(sprintf)(name, "%u.%u.%u.%u:%u",
-                      addr & 0xFF, (addr>>8) & 0xFF,
-                      (addr>>16) & 0xFF, (addr>>24) & 0xFF,
-                      vki_ntohs(sa->sin_port));
+                      (addr>>24) & 0xFF, (addr>>16) & 0xFF,
+                      (addr>>8) & 0xFF, addr & 0xFF,
+                      VG_(ntohs)(sa->sin_port));
       }
    }