From 83c9b88a1ea492cfb2d860df146d193164c0ba80 Mon Sep 17 00:00:00 2001 From: Phil <phil@secdev.org> Date: Fri, 13 Feb 2009 14:16:24 +0100 Subject: [PATCH] Cleaned up some temprary files creation --- scapy/modules/voip.py | 3 ++- scapy/packet.py | 6 +++--- scapy/plist.py | 6 +++--- scapy/sendrecv.py | 4 ++-- scapy/utils.py | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/scapy/modules/voip.py b/scapy/modules/voip.py index 4f41763d..0d0b4daf 100644 --- a/scapy/modules/voip.py +++ b/scapy/modules/voip.py @@ -13,6 +13,7 @@ from scapy.sendrecv import sniff from scapy.packet import Raw from scapy.layers.inet import IP,UDP from scapy.layers.rtp import RTP +from scapy.utils import get_temp_file def merge(x,y,sample_size=2): @@ -29,7 +30,7 @@ def merge(x,y,sample_size=2): def voip_play(s1,list=None,**kargs): - FIFO="/tmp/conv1.%i.%%i" % os.getpid() + FIFO=get_temp_file() FIFO1=FIFO % 1 FIFO2=FIFO % 2 diff --git a/scapy/packet.py b/scapy/packet.py index be6aa222..8c31aa12 100644 --- a/scapy/packet.py +++ b/scapy/packet.py @@ -8,7 +8,7 @@ from fields import StrField,ConditionalField,Emph,PacketListField from config import conf from base_classes import BasePacket,Gen,SetGen,Packet_metaclass,NewDefaultValues from volatile import VolatileValue -from utils import import_hexcap,tex_escape,colgen +from utils import import_hexcap,tex_escape,colgen,get_temp_file from error import Scapy_Exception,log_runtime try: @@ -339,7 +339,7 @@ class Packet(BasePacket): Creates an EPS file describing a packet. If filename is not provided a temporary file is created and gs is called.""" canvas = self.canvas_dump(**kargs) if filename is None: - fname = "/tmp/scapy.%i"%os.getpid() + fname = get_temp_file(autoext=".eps") canvas.writeEPSfile(fname) os.system("%s '%s.eps' &" % (conf.prog.psreader,fname)) else: @@ -350,7 +350,7 @@ Creates an EPS file describing a packet. If filename is not provided a temporary Creates a PDF file describing a packet. If filename is not provided a temporary file is created and xpdf is called.""" canvas = self.canvas_dump(**kargs) if filename is None: - fname = "/tmp/scapy.%i"%os.getpid() + fname = get_temp_file(autoext=".pdf") canvas.writePDFfile(fname) os.system("%s '%s.pdf' &" % (conf.prog.pdfreader,fname)) else: diff --git a/scapy/plist.py b/scapy/plist.py index 4eced0db..bc5c24f5 100644 --- a/scapy/plist.py +++ b/scapy/plist.py @@ -8,7 +8,7 @@ from config import conf from base_classes import BasePacket,BasePacketList from packet import Padding -from utils import do_graph,hexdump,make_table,make_lined_table,make_tex_table +from utils import do_graph,hexdump,make_table,make_lined_table,make_tex_table,get_temp_file import arch if arch.GNUPLOT: @@ -360,7 +360,7 @@ lfilter: truth function to apply to each packet to decide whether it will be dis conf.prog.psreader is called""" d = self._dump_document(**kargs) if filename is None: - filename = "/tmp/scapy.psd.%i" % os.getpid() + filename = get_temp_file(autoext=".ps") d.writePSfile(filename) os.system("%s %s.ps &" % (conf.prog.psreader,filename)) else: @@ -373,7 +373,7 @@ lfilter: truth function to apply to each packet to decide whether it will be dis conf.prog.pdfreader is called""" d = self._dump_document(**kargs) if filename is None: - filename = "/tmp/scapy.psd.%i" % os.getpid() + filename = get_temp_file(autoext=".pdf") d.writePDFfile(filename) os.system("%s %s.pdf &" % (conf.prog.pdfreader,filename)) else: diff --git a/scapy/sendrecv.py b/scapy/sendrecv.py index 85afe919..9cf0a88c 100644 --- a/scapy/sendrecv.py +++ b/scapy/sendrecv.py @@ -9,7 +9,7 @@ from data import * from arch import * from config import conf from packet import Gen -from utils import warning +from utils import warning,get_temp_file import plist from error import log_runtime,log_interactive @@ -265,7 +265,7 @@ def sendpfast(x, pps=None, mbps=None, realtime=None, loop=0, iface=None): if loop: argv.append("--loop=%i" % loop) - f = os.tempnam("scapy") + f = get_temp_file() argv.append(f) wrpcap(f, x) try: diff --git a/scapy/utils.py b/scapy/utils.py index 11cff5fd..2016f4be 100644 --- a/scapy/utils.py +++ b/scapy/utils.py @@ -21,10 +21,10 @@ from base_classes import BasePacketList ## Tools ## ########### -def get_temp_file(keep=False): +def get_temp_file(keep=False, autoext=""): f = os.tempnam("","scapy") if not keep: - conf.temp_files.append(f) + conf.temp_files.append(f+autoext) return f def sane_color(x): -- GitLab