packet lib: ipv4 option data support

also make checksum handling consistent with the other code.

Signed-off-by: HIYAMA Manabu <hiyama.manabu@po.ntts.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
HIYAMA Manabu 2012-09-26 13:07:31 +09:00 committed by FUJITA Tomonori
parent bb05f39c3a
commit 79e7d09cf0

View File

@ -14,6 +14,7 @@
# limitations under the License.
import struct
import socket
from . import packet_base
from . import packet_utils
from . import udp
@ -69,8 +70,13 @@ class ipv4(packet_base.PacketBase):
struct.pack_into(ipv4._PACK_STR, hdr, 0, version, self.tos,
self.total_length, self.identification, flags,
self.ttl, self.proto, 0, self.src, self.dst)
self.csum = packet_utils.checksum(hdr)
struct.pack_into('H', hdr, 10, self.csum)
if self.option:
assert struct.calcsize('I') >= len(self.option)
hdr[ipv4._MIN_LEN:ipv4._MIN_LEN + len(self.option)] = self.option
self.csum = socket.htons(packet_utils.checksum(hdr))
struct.pack_into('!H', hdr, 10, self.csum)
return hdr
ipv4.register_packet_type(tcp.tcp, inet.IPPROTO_TCP)