[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r8118 - trunk/gnue-common/src/utils
From: |
johannes |
Subject: |
[gnue] r8118 - trunk/gnue-common/src/utils |
Date: |
Sun, 1 Jan 2006 11:19:55 -0600 (CST) |
Author: johannes
Date: 2006-01-01 11:19:54 -0600 (Sun, 01 Jan 2006)
New Revision: 8118
Modified:
trunk/gnue-common/src/utils/uuid.py
Log:
Added alternative way for detecting available network interfaces (thanks
to Ross Golder) and implemented an automatic fallback to
random-generated UUID if no network interface could be found. This
fixes UUID generation on 64-bit architectures and Mac OS. The latter one
still lacks node-based UUIDs.
Modified: trunk/gnue-common/src/utils/uuid.py
===================================================================
--- trunk/gnue-common/src/utils/uuid.py 2005-12-31 09:27:00 UTC (rev 8117)
+++ trunk/gnue-common/src/utils/uuid.py 2006-01-01 17:19:54 UTC (rev 8118)
@@ -228,22 +228,15 @@
result = []
if sys.platform == 'linux2':
- sfhd = socket.socket (socket.AF_INET, socket.SOCK_DGRAM)
-
try:
- buffer = array.array ('c', '\0' * 1024)
- (addr, length) = buffer.buffer_info ()
- ifconf = struct.pack ("iP", length, addr)
- data = fcntl.ioctl (sfhd.fileno (), self.SIOCGIFCONF, ifconf)
+ result = self.__getInterfacesFromProc ()
- size, ptr = struct.unpack ("iP", data)
- for idx in range (0, size, 32):
- ifconf = buffer.tostring () [idx:idx+32]
- name = struct.unpack ("16s16s", ifconf) [0].split ('\0', 1) [0]
- result.append (name)
+ except:
+ try:
+ result = self.__getInterfacesFromSockets ()
- finally:
- sfhd.close ()
+ except:
+ pass
elif sys.platform == 'win32' and _HAS_GETOBJECT:
result = [i for i in GetObject ('winmgmts:').ExecQuery ("SELECT * FROM "
@@ -253,6 +246,52 @@
# ---------------------------------------------------------------------------
+ # Get a list of available network interfaces from /proc/net/dev
+ # ---------------------------------------------------------------------------
+
+ def __getInterfacesFromProc (self):
+
+ result = []
+ nfhd = open ('/proc/net/dev', 'r')
+
+ try:
+ for line in [l.strip () for l in nfhd.readlines () if ':' in l]:
+ result.append (line.split (':', 1) [0])
+
+ finally:
+ nfhd.close ()
+
+ return result
+
+
+ # ---------------------------------------------------------------------------
+ # Get a list of network interfaces via sockets
+ # ---------------------------------------------------------------------------
+
+ def __getInterfacesFromSockets (self):
+
+ result = []
+ sfhd = socket.socket (socket.AF_INET, socket.SOCK_DGRAM)
+
+ try:
+ buffer = array.array ('c', '\0' * 1024)
+ (addr, length) = buffer.buffer_info ()
+ ifconf = struct.pack ("iP", length, addr)
+ data = fcntl.ioctl (sfhd.fileno (), self.SIOCGIFCONF, ifconf)
+
+ size, ptr = struct.unpack ("iP", data)
+ for idx in range (0, size, 32):
+ ifconf = buffer.tostring () [idx:idx+32]
+ name = struct.unpack ("16s16s", ifconf) [0].split ('\0', 1) [0]
+ result.append (name)
+
+ finally:
+ sfhd.close ()
+
+ return result
+
+
+ # ---------------------------------------------------------------------------
# Check if a hardware address is NULL (all zeros)
# ---------------------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r8118 - trunk/gnue-common/src/utils,
johannes <=