From 735fd8aec4bc0b7992e2604231433e1aa23d7c1a Mon Sep 17 00:00:00 2001 From: Christian Ulrich Date: Sat, 24 Oct 2020 19:15:46 +0200 Subject: [PATCH] use random ID in IP header --- ip_packet.nim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ip_packet.nim b/ip_packet.nim index 2a5063d..8997680 100644 --- a/ip_packet.nim +++ b/ip_packet.nim @@ -1,6 +1,7 @@ from nativesockets import ntohs, ntohl, htons, htonl from net import IpAddress, IpAddressFamily, Port, `$` from posix import InAddr, inet_ntoa +from random import randomize, rand import unittest type @@ -134,6 +135,7 @@ proc tcpChecksum(buffer: string): uint16 = result = not checksum.uint16 proc serialize*(packet: IpPacket): string = + randomize() case packet.protocol of tcp: result = newString(sizeof(Ip) + sizeof(Tcphdr)) @@ -146,7 +148,7 @@ proc serialize*(packet: IpPacket): string = ipHeader.ip_v = 4 ipHeader.ip_tos = 0 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_ttl = packet.ipTTL ipHeader.ip_p = 6.cuchar