diff --git a/scapy/arch/common.py b/scapy/arch/common.py new file mode 100644 index 0000000000000000000000000000000000000000..39e8c457d3c0e2b1347cd074acffb3958decf14d --- /dev/null +++ b/scapy/arch/common.py @@ -0,0 +1,21 @@ +## This file is part of Scapy +## See http://www.secdev.org/projects/scapy for more informations +## Copyright (C) Philippe Biondi <phil@secdev.org> +## This program is published under a GPLv2 license + +""" +Functions common to different architectures +""" + +import socket +from fcntl import ioctl +import struct + + +def get_if(iff, cmd): + """Ease SIOCGIF* ioctl calls""" + + sck = socket.socket() + ifreq = ioctl(sck, cmd, struct.pack("16s16x", iff)) + sck.close() + return ifreq diff --git a/scapy/arch/linux.py b/scapy/arch/linux.py index ec0495f16bd308edf9c8619071e84afe1aee1064..9014c3433869cb21f2d92a8bb01fff10b41e6f28 100644 --- a/scapy/arch/linux.py +++ b/scapy/arch/linux.py @@ -19,6 +19,7 @@ from scapy.data import * from scapy.supersocket import SuperSocket import scapy.arch from scapy.error import warning, Scapy_Exception +from scapy.arch.common import get_if @@ -276,15 +277,6 @@ def read_routes6(): return routes - - -def get_if(iff,cmd): - s=socket.socket() - ifreq = ioctl(s, cmd, struct.pack("16s16x",iff)) - s.close() - return ifreq - - def get_if_index(iff): return int(struct.unpack("I",get_if(iff, SIOCGIFINDEX)[16:20])[0])