use random ID in IP header

This commit is contained in:
Christian Ulrich 2020-10-24 19:15:46 +02:00
parent ca88330b4d
commit 735fd8aec4
No known key found for this signature in database
GPG Key ID: 8241BE099775A097
1 changed files with 3 additions and 1 deletions

View File

@ -1,6 +1,7 @@
from nativesockets import ntohs, ntohl, htons, htonl from nativesockets import ntohs, ntohl, htons, htonl
from net import IpAddress, IpAddressFamily, Port, `$` from net import IpAddress, IpAddressFamily, Port, `$`
from posix import InAddr, inet_ntoa from posix import InAddr, inet_ntoa
from random import randomize, rand
import unittest import unittest
type type
@ -134,6 +135,7 @@ proc tcpChecksum(buffer: string): uint16 =
result = not checksum.uint16 result = not checksum.uint16
proc serialize*(packet: IpPacket): string = proc serialize*(packet: IpPacket): string =
randomize()
case packet.protocol case packet.protocol
of tcp: of tcp:
result = newString(sizeof(Ip) + sizeof(Tcphdr)) result = newString(sizeof(Ip) + sizeof(Tcphdr))
@ -146,7 +148,7 @@ proc serialize*(packet: IpPacket): string =
ipHeader.ip_v = 4 ipHeader.ip_v = 4
ipHeader.ip_tos = 0 ipHeader.ip_tos = 0
ipHeader.ip_len = htons(sizeof(Ip).uint16 + sizeof(TcpHdr).uint16) ipHeader.ip_len = htons(sizeof(Ip).uint16 + sizeof(TcpHdr).uint16)
ipHeader.ip_id = htons(54321) # FIXME = random number ipHeader.ip_id = rand(cushort)
ipHeader.ip_off = 0 ipHeader.ip_off = 0
ipHeader.ip_ttl = packet.ipTTL ipHeader.ip_ttl = packet.ipTTL
ipHeader.ip_p = 6.cuchar ipHeader.ip_p = 6.cuchar