diff --git a/scapy/modules/voip.py b/scapy/modules/voip.py index 4f41763d8962660e173c2607f8e68e668d928f9b..0d0b4daf93c50cc450d20c849fbdb6a2059f2399 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 be6aa222d02490f46d9329d154b8c6632a07359d..8c31aa12bd81260c9d3d1e252da567ad96fa517a 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 4eced0db3967dfbd2597fbfef1bc44ecd8d2cdad..bc5c24f56ee399bc3c59f2b0578f8260199de89e 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 85afe919b594e8f10678771047e9c31f053cc8a9..9cf0a88c5d8639afd5aaf8998d7c8a22813494c8 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 11cff5fd8aba86ea22e5857b01f9da23a11a8392..2016f4befe9961599473f21febc58cc816ebcfde 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):