JulianSchmid / etherparse

A rust library for parsing ethernet & ethernet using protocols.
Apache License 2.0
299 stars 53 forks source link

Incorrect example #41

Closed StackOverflowExcept1on closed 1 year ago

StackOverflowExcept1on commented 1 year ago

I'm trying to use custom udp packet builder with almost same code: https://github.com/JulianSchmid/etherparse/blob/master/examples/write_ipv4_udp.rs

some context to show the error later

//setup the actual payload of the udp packet
let udp_payload = [1,2,3,4,5,6,7,8];

//source ip address
[192,168,1,42],
//destination ip address
[192,168,1,1]
$ cargo run --example=write_ipv4_udp
[1, 2, 3, 4, 5, 6, 11, 12, 13, 14, 15, 16, 8, 0, 69, 0, 0, 36, 0, 0, 64, 0, 20, 17, 227, 77, 192, 168, 1, 42, 192, 168, 1, 1, 0, 0, 0, 42, 0, 16, 108, 20]

IPv4: (start from 0x45/69)

[69, 0, 0, 36, 0, 0, 64, 0, 20, 17, 227, 77, 192, 168, 1, 42, 192, 168, 1, 1, 0, 0, 0, 42, 0, 16, 108, 20]

I'm using raw sockets to send it and Wireshark to view packets image1 software shows that UDP packet is invalid image2

payload length is calculated as udp_header_len + payload.len() = 8 + 8 = 16 but as we see there is no payload at the generated packet

JulianSchmid commented 1 year ago

Good catch & thanks for the fix.