Last active
May 2, 2016 13:52
-
-
Save hjr3/74c7f81d4bb349ca1e71efccde54f4be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Building a Ipv4Header struct | |
/// | |
/// Ipv4Header has the same byte representation as `struct ip` in C. The | |
/// builder pattern provides a better interface for dealing with byte order | |
/// specific unions. It also means we can use types like `Ipv4Addr` instead | |
/// of `c::in_addr`. | |
let ip: Ipv4Header = Ipv4HeaderBuilder::new() // sets version and internet header length (ihl) | |
.tos(Tos::low_delay()) | |
.data_length(::std::mem::size_of::<CarpHeader>()) // calculates proper total length | |
.random_id() | |
.flags(Flags::dont_fragment()) | |
.ttl(255) | |
.protocol(Protocol::Carp) | |
.source_address(FromStr::from_str("10.0.0.2").unwrap()) | |
.destination_address(FromStr::from_str("10.0.0.3").unwrap()) | |
.build(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment