[tor-commits] [arm/master] Accounting for big-endian architectures in proc

atagar at torproject.org atagar at torproject.org
Sat Jan 7 18:41:54 UTC 2012


commit 8ec7095d79ecad9d3432193a2b1f9fdefab8d7f3
Author: Damian Johnson <atagar at torproject.org>
Date:   Sat Jan 7 10:38:34 2012 -0800

    Accounting for big-endian architectures in proc
    
    The proc utils were assuming that encoded ip addresses were little-endian. This
    was fixed in the project these utils are based on (psutil) and I'm adopting the
    fix...
    https://code.google.com/p/psutil/issues/detail?id=201
    https://trac.torproject.org/projects/tor/ticket/4777
    
    This evidently occures on OpenWRT (ar71xx), thanks to swalker for the catch!
---
 src/util/procTools.py |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/src/util/procTools.py b/src/util/procTools.py
index a592989..39b5407 100644
--- a/src/util/procTools.py
+++ b/src/util/procTools.py
@@ -288,7 +288,15 @@ def _decodeProcAddressEncoding(addr):
   # The IPv4 address portion is a little-endian four-byte hexadecimal number.
   # That is, the least significant byte is listed first, so we need to reverse
   # the order of the bytes to convert it to an IP address.
-  ip = socket.inet_ntop(socket.AF_INET, base64.b16decode(ip)[::-1])
+  #
+  # This needs to account for the endian ordering as per...
+  # http://code.google.com/p/psutil/issues/detail?id=201
+  # https://trac.torproject.org/projects/tor/ticket/4777
+  
+  if sys.byteorder == 'little':
+    ip = socket.inet_ntop(socket.AF_INET, base64.b16decode(ip)[::-1])
+  else:
+    ip = socket.inet_ntop(socket.AF_INET, base64.b16decode(ip))
   
   return (ip, port)
 



More information about the tor-commits mailing list