Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fragment size re calculation inside fragment funciton #2424

Closed
inoyatov opened this issue Jan 21, 2020 · 1 comment
Closed

Fragment size re calculation inside fragment funciton #2424

inoyatov opened this issue Jan 21, 2020 · 1 comment

Comments

@inoyatov
Copy link

Can somebody explain why fragment size is re-calculating in line 554? I need payload exactly 100 bytes. But after re-calculation i got 104 bytes. What is reason? Thank you in advance.

scapy/scapy/layers/inet.py

Lines 552 to 577 in 90c8d82

def fragment(self, fragsize=1480):
"""Fragment IP datagrams"""
fragsize = (fragsize + 7) // 8 * 8
lst = []
fnb = 0
fl = self
while fl.underlayer is not None:
fnb += 1
fl = fl.underlayer
for p in fl:
s = raw(p[fnb].payload)
nb = (len(s) + fragsize - 1) // fragsize
for i in range(nb):
q = p.copy()
del(q[fnb].payload)
del(q[fnb].chksum)
del(q[fnb].len)
if i != nb - 1:
q[fnb].flags |= 1
q[fnb].frag += i * fragsize // 8
r = conf.raw_layer(load=s[i * fragsize:(i + 1) * fragsize])
r.overload_fields = p[fnb].payload.overload_fields.copy()
q.add_payload(r)
lst.append(q)
return lst

@gpotter2
Copy link
Member

gpotter2 commented Jan 21, 2020

From https://tools.ietf.org/html/rfc791#section-3.2 (page 25, top):

If an internet datagram is fragmented, its data portion must be broken on 8 octet boundaries.

To answer your question, fragment size must be a multiple of 8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants