Skip to content
Snippets Groups Projects
Commit c2ff2ce9 authored by Pierre LALET's avatar Pierre LALET
Browse files

Pad packet when needed (fixes #90)

parent 9434f75b
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@ from select import select
from fcntl import ioctl
import scapy.utils
import scapy.utils6
from scapy.packet import Packet, Padding
from scapy.config import conf
from scapy.data import *
from scapy.supersocket import SuperSocket
......@@ -398,14 +399,15 @@ class L3PacketSocket(SuperSocket):
sx = str(ll(x))
x.sent_time = time.time()
self.outs.sendto(sx, sdto)
except socket.error,msg:
except socket.error, msg:
x.sent_time = time.time() # bad approximation
if conf.auto_fragment and msg[0] == 90:
if msg[0] == 22 and len(sx) < conf.min_pkt_size:
self.outs.send(sx + "\x00" * (conf.min_pkt_size - len(sx)))
elif conf.auto_fragment and msg[0] == 90:
for p in x.fragment():
self.outs.sendto(str(ll(p)), sdto)
else:
raise
......@@ -460,6 +462,17 @@ class L2Socket(SuperSocket):
q = conf.raw_layer(pkt)
q.time = get_last_packet_timestamp(self.ins)
return q
def send(self, x):
try:
return SuperSocket.send(self, x)
except socket.error, msg:
if msg[0] == 22 and len(x) < conf.min_pkt_size:
padding = "\x00" * (conf.min_pkt_size - len(x))
if isinstance(x, Packet):
return SuperSocket.send(self, x / Padding(load=padding))
else:
return SuperSocket.send(self, str(x) + padding)
raise
class L2ListenSocket(SuperSocket):
......
......@@ -345,6 +345,7 @@ extensions_paths: path or list of paths where extensions are to be looked for
L3socket = None
L2socket = None
L2listen = None
min_pkt_size = 60
histfile = os.path.join(os.path.expanduser("~"), ".scapy_history")
padding = 1
except_filter = ""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment