djhenderson / dpkt

Automatically exported from code.google.com/p/dpkt
Other
1 stars 0 forks source link

dpkt.ip.IP constructor generates packet with incorrect 'len' field. #55

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
### Begin sample code ###
from dpkt import ip

ip1 = ip.IP(data="Hello world!")
ip2 = ip.IP(str(ip1))
ip1.len = ip1.len + 12
ip3 = ip.IP(str(ip1))
print repr(str(ip1))
print repr(str(ip2))
print repr(str(ip3))

### End sample code ###

What is the expected output? What do you see instead?
Expect ip1 to be the same as ip2, ip3 to have a 'len' field 12 too large.
Actual ip2 is truncated to have no payload, ip3 is same as ip1.

What version of the product are you using? On what operating system?
dpkt 1.6 on Ubuntu 10.10 (package 1.6+svn54-1)

Please provide any additional information below.

Original issue reported on code.google.com by googa...@jlm.ofb.net on 9 Dec 2010 at 10:05

GoogleCodeExporter commented 9 years ago
Instead of using the len field direcly, first calculate it through the __len__()
and then use the value.
here is a suggested patch

Original comment by pchemist...@gmail.com on 10 Mar 2015 at 2:54

Attachments: