Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions scapy/arch/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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
Expand Down Expand Up @@ -394,18 +395,18 @@ def send(self, x):
sdto = (iff, conf.l3types[type(x)])
if sn[3] in conf.l2types:
ll = lambda x:conf.l2types[sn[3]]()/x
sx = str(ll(x))
x.sent_time = time.time()
try:
sx = str(ll(x))
x.sent_time = time.time()
self.outs.sendto(sx, sdto)
except socket.error,msg:
x.sent_time = time.time() # bad approximation
if conf.auto_fragment and msg[0] == 90:
except socket.error, msg:
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




Expand Down Expand Up @@ -460,6 +461,17 @@ def recv(self, x=MTU):
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):
Expand Down
1 change: 1 addition & 0 deletions scapy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ class Conf(ConfClass):
L3socket = None
L2socket = None
L2listen = None
min_pkt_size = 60
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you choose 60 ?

According to the page linked in issue #90 this value could be lower. For example, on my laptop sendp("A"*15) works fine while sendp("A"*14) fails. 15 is indeed equal to len(str(Ether())). I wonder if it could be computed dynamically.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not the case for every driver, I have one example where 58 bytes are needed.

I don't think that more than 60 bytes could be needed, since that is the minimum ethernet length, and I think it's fine to have the value set to 60 by default as it can be easily configured.

Also, I have not found a way to find this value dynamically (other than by bisecting, and I don't think that trying multiple values is a good option).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guedou I have updated the description on #90 to give more information.

histfile = os.path.join(os.path.expanduser("~"), ".scapy_history")
padding = 1
except_filter = ""
Expand Down