You can't receive a raw tcp header from TcpStream, for that you'd need a raw socket. What exactly do you need from the header? Most of the information is retrievable...
On Unix/Linux you can use as_raw_fd, and then call setsockopt (requires unsafe).
AFAIK it doesn't make sense to set IP_DONTFRAG on a TCP socket, it's only for UDP/ICMP/raw IP...
Thanks for reply.
I need tcp header for debug.
I have strange problem with tcp - I am getting incomplete data in a packet, fragmented data (struct bytes) in Rust. But in the wireshark data is complete (same device).
That's not a bug. It's a misunderstanding of TCP. TCP offers a byte streaming, not packet transmission. There are no frame/packet/etc boundaries. Each intermediary (e.g. the Kernels send and receive buffers) are free to change frame boundaries as long as the overall data-stream stays intact.
If you need packet boundaries, you need to define an application protocol on top of TCP.
In Naim's example, the read_exact method is used. It will ensure that the specified number of bytes is read by repeatedly calling read until the total number of returned bytes matches the requested length.