Date: Thu, 20 Aug 2009 12:22:00 GMT From: Aurélien Ansel <aurelien.ansel@netasq.com> To: freebsd-gnats-submit@FreeBSD.org Subject: ports/137990: Update of net/Scapy 2.0.1_3 Message-ID: <200908201222.n7KCM0Ga040354@www.freebsd.org> Resent-Message-ID: <200908201230.n7KCU4N0085281@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 137990 >Category: ports >Synopsis: Update of net/Scapy 2.0.1_3 >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: maintainer-update >Submitter-Id: current-users >Arrival-Date: Thu Aug 20 12:30:03 UTC 2009 >Closed-Date: >Last-Modified: >Originator: Aurélien Ansel >Release: 7.2-STABLE >Organization: NETASQ >Environment: FreeBSD aureliena2.netasq.com 7.2-STABLE FreeBSD 7.2-STABLE #17: Thu Aug 13 14:18:11 CEST 2009 root@aureliena2.netasq.com:/usr/obj/usr/src/sys/NOYAU i386 >Description: * Fix a missing import * Fix a bug due to libdnet with a patch that use BPF and libpcap >How-To-Repeat: >Fix: Patch attached with submission follows: diff -rNu -x '.git*' /usr/ports/net/scapy/Makefile ./Makefile --- /usr/ports/net/scapy/Makefile 2009-07-28 16:11:27.000000000 +0200 +++ ./Makefile 2009-08-20 11:50:57.000000000 +0200 @@ -8,7 +8,7 @@ PORTNAME= scapy PORTVERSION= 2.0.1 -PORTREVISION= 2 +PORTREVISION= 3 CATEGORIES= net MASTER_SITES= http://secdev.org/projects/scapy/files/ @@ -33,7 +33,8 @@ NMAP "Support for nmap OS signatures database" off \ MANUF "Support for wireshark's MANUF MAC database" off \ VPYTHON "Support for 3D representation of traceroute" off \ - SOX "Support for VoIP" off + SOX "Support for VoIP" off \ + BPF "Patch to use BPF and libpcap instead of libdnet" on .include <bsd.port.pre.mk> @@ -78,6 +79,12 @@ RUN_DEPENDS+= ${LOCALBASE}/bin/sox:${PORTSDIR}/audio/sox .endif +## The original patch comes from the Trac of Scapy +## http://trac.secdev.org/scapy/ticket/165 +.if defined(WITH_BPF) +EXTRA_PATCHES+= ${PATCHDIR}/libdnet-for-BSD.patch +.endif + SCAPY_MODULES= nmap.py p0f.py queso.py post-patch: diff -rNu -x '.git*' /usr/ports/net/scapy/files/libdnet-for-BSD.patch ./files/libdnet-for-BSD.patch --- /usr/ports/net/scapy/files/libdnet-for-BSD.patch 1970-01-01 01:00:00.000000000 +0100 +++ ./files/libdnet-for-BSD.patch 2009-08-20 10:44:45.000000000 +0200 @@ -0,0 +1,184 @@ +--- scapy/arch/__init__.py ++++ scapy/arch/__init__.py +@@ -46,6 +46,8 @@ NETBSD = sys.platform.startswith("netbsd") + DARWIN=sys.platform.startswith("darwin") + SOLARIS=sys.platform.startswith("sunos") + ++BROKEN_BPF = FREEBSD or DARWIN ++ + X86_64 = (os.uname()[4] == 'x86_64') + + +--- scapy/arch/bsd.py ++++ scapy/arch/bsd.py +@@ -8,3 +8,129 @@ + LOOPBACK_NAME="lo0" + + from unix import * ++ ++if conf.use_dnet == 0 and conf.use_pcap == 1: ++ ++ BIOCSETIF = -2145369492 # 0x8020426c ++ BROKEN_BPF = False ++ ++ def get_if_raw_addr(ifname): ++ try: ++ f = os.popen("%s %s" % (conf.prog.ifconfig, ifname)) ++ except OSError, msg: ++ raise Scapy_Exception("Failed to execute ifconfig: (%s)" % msg) ++ l = f.readlines() ++ ip = "" ++ for i in l: ++ if i.find("netmask") >= 0: ++ ip = i ++ break ++ if ip == "": ++ raise Scapy_Exception("Error in attempting to get hw address for interface [%s]" % ifname) ++ ip = ip.split(' ')[1] ++ return socket.inet_pton(socket.AF_INET, ip) ++ ++ def get_if_raw_hwaddr(ifname): ++ if ifname[:2] == "lo": ++ return (772, '\x00'*6) ++ try: ++ f = os.popen("%s %s" % (conf.prog.ifconfig, ifname)) ++ except OSError, msg: ++ warning("Failed to execute ifconfig: (%s)" % msg) ++ return "\0\0\0\0" ++ l = f.readlines() ++ mac = "" ++ for i in l: ++ if i.find("ether") >= 0 or i.find("lladdr") >= 0 or i.find("address") >= 0: ++ mac = i ++ break ++ if mac == "": ++ return "\0\0\0\0" ++ mac = mac.split(' ')[1].split(':') ++ mac = map(lambda x: chr(int(x, 16)), mac) ++ return (1, "".join(mac)) ++ ++ def get_dev_bpf(): ++ fd = None ++ for bpf in range(0, 8): ++ try: ++ fd = os.open('/dev/bpf%i' % bpf, os.O_RDWR) ++ if fd: ++ break ++ except OSError, err: ++ continue ++ if fd == None: ++ log_loading.warning("No /dev/bpf is available !") ++ bpf = None ++ return (fd, bpf) ++ ++ class L2bpfpcapSocket(L2pcapListenSocket): ++ desc = "read/write packets at layer 2 using libpcap and BPF" ++ ++ def __init__(self, iface=None, type=ETH_P_ALL, promisc=None, filter=None, nofilter=0): ++ ++ if iface == None: ++ iface = conf.iface ++ ++ self.ins = None ++ L2pcapListenSocket.__init__(self, iface=iface, type=type, promisc=promisc, filter=filter) ++ self.closed = False ++ ++ (self.outs, self.dev_bpf) = get_dev_bpf() ++ ++ try: ++ ioctl(self.outs, ++ BIOCSETIF, ++ struct.pack('16s16x', self.iface)) ++ except IOError, err: ++ warning("BIOCSETIF failed on %s" % self.iface) ++ ++ def send(self, x): ++ return os.write(self.outs, str(x)) ++ ++ def __del__(self): ++ if open_pcap != None and hasattr(self, "close"): ++ self.close() ++ ++ def close(self): ++ if self.closed == False: ++ self.closed = True ++ if hasattr(self, "outs"): ++ os.close(self.outs) ++ if hasattr(self, "ins"): ++ self.ins.close() ++ ++ class L3bpfpcapSocket(L2bpfpcapSocket): ++ desc = "read/write packets at layer 3 using libpcap and BPF" ++ ++ def recv(self, x): ++ return L2pcapListenSocket.recv(self, x).payload ++ ++ def send(self, x): ++ if isinstance(x, IPv6): ++ iff,a,gw = conf.route6.route(x.dst) ++ elif hasattr(x,"dst"): ++ iff,a,gw = conf.route.route(x.dst) ++ else: ++ iff = conf.iface ++ ++ try: ++ ioctl(self.outs, ++ BIOCSETIF, ++ struct.pack('16s16x', iff)) ++ except IOError, err: ++ warning("BIOCSETIF failed on %s" % iff) ++ ++ ll = self.ins.datalink() ++ if ll in conf.l2types: ++ cls = conf.l2types[ll] ++ else: ++ cls = conf.default_l2 ++ warning("Unable to guess datalink type (interface=%s linktype=%i). Using %s" % (self.iface, ll, cls.name)) ++ ++ frame = str(cls()/x) ++ x.sent_time = time.time() ++ L2bpfpcapSocket.send(self, frame) ++ ++ conf.L3socket=L3bpfpcapSocket ++ conf.L2socket=L2bpfpcapSocket + + +--- scapy/arch/pcapdnet.py ++++ scapy/arch/pcapdnet.py +@@ -40,8 +40,16 @@ if conf.use_pcap: + def __init__(self, *args, **kargs): + self.pcap = pcap.pcapObject() + self.pcap.open_live(*args, **kargs) ++ self.closed = False + def setfilter(self, filter): + self.pcap.setfilter(filter, 0, 0) ++ def __del__(self): ++ self.close() ++ def close(self): ++ import os ++ if self.closed == False: ++ os.close(self.pcap.fileno()) ++ self.closed = True + def next(self): + c = self.pcap.next() + if c is None: +@@ -99,6 +107,7 @@ if conf.use_pcap: + self.ins.setfilter(filter) + + def close(self): ++ print "Father closed" + del(self.ins) + + def recv(self, x): + + +--- scapy/config.py ++++ scapy/config.py +@@ -43,6 +43,7 @@ class ProgPath(ConfClass): + tcpreplay = "tcpreplay" + hexedit = "hexer" + wireshark = "wireshark" ++ ifconfig = "ifconfig" + + class Resolve: + def __init__(self): diff -rNu -x '.git*' /usr/ports/net/scapy/files/patch-scapy-sendrecv.py ./files/patch-scapy-sendrecv.py --- /usr/ports/net/scapy/files/patch-scapy-sendrecv.py 2009-07-28 16:11:27.000000000 +0200 +++ ./files/patch-scapy-sendrecv.py 2009-08-20 11:06:33.000000000 +0200 +@@ -9,9 +9,10 @@ from arch import * from config import conf from packet import Gen @@ -8,4 +8,7 @@ +from utils import warning,PcapReader import plist from error import log_runtime,log_interactive ++from base_classes import SetGen + ################# + ## Debug class ## >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200908201222.n7KCM0Ga040354>