From 2018bfa381e32d2e896ca7c8e47f68f5249dbedd Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Mon, 10 Oct 2016 17:43:38 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BE=D0=BF=D1=80=D0=B5=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20slave=20=D0=B4=D0=BB=D1=8F=20=D1=81=D0=B5=D1=82?= =?UTF-8?q?=D0=B5=D0=B2=D1=8B=D1=85=20=D1=83=D1=81=D1=82=D1=80=D0=BE=D0=B9?= =?UTF-8?q?=D1=81=D1=82=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pym/calculate/lib/utils/ip.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pym/calculate/lib/utils/ip.py b/pym/calculate/lib/utils/ip.py index 1f6a25f..e680851 100644 --- a/pym/calculate/lib/utils/ip.py +++ b/pym/calculate/lib/utils/ip.py @@ -50,6 +50,8 @@ SIOCGIFHWADDR = 0x8927 # Resources allocated IFF_RUNNING = 0x40 +IFF_MASTER = 0x400 +IFF_SLAVE = 0x800 # ip digit from 0|1-255|254 (template) IP_DIG = "[%s-9]|(?:1[0-9]|[1-9])[0-9]|2[0-4][0-9]|25[0-%s]" @@ -243,8 +245,7 @@ def getIp(iface): ip = struct.unpack('16sH2x4s8x', res)[2] return socket.inet_ntoa(ip) - -def getPlugged(iface): +def checkFlag(iface, flag): sockfd = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) ifreq = struct.pack('16sH14s', iface, socket.AF_INET, '\x00' * 14) try: @@ -253,8 +254,16 @@ def getPlugged(iface): return False finally: sockfd.close() - return bool(struct.unpack('16sH2x4s8x', res)[1] & IFF_RUNNING) + return bool(struct.unpack('16sH2x4s8x', res)[1] & flag) + +def getPlugged(iface): + return checkFlag(iface, IFF_RUNNING) + +def isSlaveInterface(iface): + return checkFlag(iface, IFF_SLAVE) +def isMasterInterface(iface): + return checkFlag(iface, IFF_MASTER) def getMask(iface): """