Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #736 from rnavarro/master

Fix for automatic gateway interface IP calculation
  • Loading branch information...
commit 8a88525dc38b4a36930b7935d8d071f1b7ea925d 2 parents 2054c31 + 228abb5
@primalmotion primalmotion authored
Showing with 13 additions and 1 deletion.
  1. +13 −1 ArchipelAgent/archipel-core/archipelcore/utils.py
View
14 ArchipelAgent/archipel-core/archipelcore/utils.py
@@ -28,6 +28,7 @@
import ConfigParser
import socket
import struct
+import fcntl
import inspect
import logging
import logging.handlers
@@ -188,4 +189,15 @@ def get_default_gateway_interface():
if fields[1] != '00000000' or not int(fields[3], 16) & 2:
continue
- return socket.inet_ntoa(struct.pack("<L", int(fields[2], 16)))
+ return get_ip_address(fields[0])
+
+def get_ip_address(ifname):
+ """
+ Returns the IP address associated with the given interface
+ """
+ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ return socket.inet_ntoa(fcntl.ioctl(
+ s.fileno(),
+ 0x8915, # SIOCGIFADDR
+ struct.pack('256s', ifname[:15])
+ )[20:24])
Please sign in to comment.
Something went wrong with that request. Please try again.