use random ID in IP header
This commit is contained in:
parent
ca88330b4d
commit
735fd8aec4
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue