[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

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



commit a31aa4ad506ccf4e529182e31d0a84966e38d6e1
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Mon Jan 30 00:02:55 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!
    
    This is the same as arm commit 8ec7095d79ecad9d3432193a2b1f9fdefab8d7f3
---
 stem/util/proc.py |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/stem/util/proc.py b/stem/util/proc.py
index bf91ace..cbfc3c5 100644
--- a/stem/util/proc.py
+++ b/stem/util/proc.py
@@ -369,7 +369,15 @@ def _decode_proc_address_encoding(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)
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits