remove wrong htonl; don't hard-code ip packet size

This commit is contained in:
Christian Ulrich 2020-07-17 20:04:45 +02:00
parent 95f074e202
commit 32060fe9dc
No known key found for this signature in database
GPG Key ID: 8241BE099775A097
1 changed files with 3 additions and 3 deletions

View File

@ -100,12 +100,12 @@ proc parseEthernetPacket*(input: string): IpPacket =
proc serialize*(packet: IpPacket): string = proc serialize*(packet: IpPacket): string =
case packet.protocol case packet.protocol
of tcp: of tcp:
let srcIp = InAddr(s_addr: htonl(cast[uint32](packet.tcpIpSrc.address_v4))) let srcIp = InAddr(s_addr: cast[uint32](packet.tcpIpSrc.address_v4))
let dstIp = InAddr(s_addr: htonl(cast[uint32](packet.tcpIpDst.address_v4))) let dstIp = InAddr(s_addr: cast[uint32](packet.tcpIpDst.address_v4))
var ipHeader = Ip(ip_hl: 5, var ipHeader = Ip(ip_hl: 5,
ip_v: 4, ip_v: 4,
ip_tos: 0, ip_tos: 0,
ip_len: htons(40), ip_len: sizeof(Ip).uint16 + sizeof(TcpHdr).uint16,
ip_id: htons(54321), # FIXME: random number ip_id: htons(54321), # FIXME: random number
ip_off: 0, ip_off: 0,
ip_ttl: 64, ip_ttl: 64,