PacketInfo
#struct PacketInfoWhat Parse read from one IP packet: version, protocol, addresses, ports, TCP flags and where the payload starts.
| Name | Type | Description |
|---|---|---|
valid | bool = false | False when the bytes are not a complete IPv4 or IPv6 packet. |
version | int = 0 | 4 or 6. |
proto | int = 0 | The transport protocol number, for example proto_tcp. |
src | str = "" | Source address as text. |
dst | str = "" | Destination address as text. |
sport | int = 0 | Source port for TCP and UDP, 0 otherwise. |
dport | int = 0 | Destination port for TCP and UDP, 0 otherwise. |
flags | int = 0 | The TCP flag bits, see tcp_syn and the others. |
header_len | int = 0 | Length of the IP header in bytes. |
payload_offset | int = 0 | Offset of the transport payload from the start of the packet. |
payload_len | int = 0 | Length of the transport payload. |
total | int = 0 | Total length of the packet from its header. |
fragment | bool = false | True for an IPv4 fragment. The stack drops fragments. |
import net.tun
func main():
body := "hi"
pk := tun.BuildTcp4(
"172.19.0.1", 40000, "93.184.216.34", 443, 1 as i64, 0 as i64, tun.tcp_syn, body as void*,
2
)
info := tun.Parse(pk.data, pk.len)
println info.valid,
info.version,
info.proto == tun.proto_tcp,
info.src,
info.sport,
info.dst,
info.dport
println "syn",
(info.flags & tun.tcp_syn) != 0,
"ack",
(info.flags & tun.tcp_ack) != 0,
"payload",
info.payload_len,
"of",
info.total
println "checksums ok", tun.ChecksumsOk(pk.data, pk.len)
p := pk.data as u8*
p[8] = 32 as u8
println "after edit", tun.ChecksumsOk(pk.data, pk.len)
tun.FinishChecksums(pk.data, pk.len)
println "after finish", tun.ChecksumsOk(pk.data, pk.len)
println "header sum", tun.Checksum(pk.data, 20)
println "rfc 1624", tun.ChecksumAdjust(56623, 21845, 12933)
udp := tun.BuildUdp4("10.0.0.2", 5000, "10.0.0.1", 53, null, 0)
u := tun.Parse(udp.data, udp.len)
println "udp", u.proto == tun.proto_udp, u.header_len, u.payload_offset, u.fragment
println "other flags", tun.tcp_fin, tun.tcp_rst, tun.tcp_psh, tun.proto_icmp, tun.proto_icmp6
tun.FreePacket(pk)
tun.FreePacket(udp)
endtrue 4 true 172.19.0.1 40000 93.184.216.34 443 syn true ack false payload 2 of 42 checksums ok true after edit false after finish true header sum 0 rfc 1624 0 udp true 20 28 false other flags 1 4 8 1 58