Skip to content

Commit

Permalink
README.md: remove main() and de-indent the usage example
Browse files Browse the repository at this point in the history
  • Loading branch information
edigaryev committed Jun 8, 2022
1 parent cc9592c commit 2c02c25
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,30 @@ Ensure that your software either has an `com.apple.vm.networking` entitlement or
Start a NAT interface and receive some packets destined to it:

```rust
fn main() {
let shared_mode = Shared {
subnet_options: None,
..Default::default()
};

let mut iface = Interface::new(Mode::Shared(shared_mode), Options::default()).unwrap();

let (tx, rx) = sync::mpsc::sync_channel(0);

iface.set_event_callback(Events::PACKETS_AVAILABLE, move |events, params| {
if let Some(Parameter::EstimatedPacketsAvailable(pkts)) = params.get(ParameterKind::EstimatedPacketsAvailable) {
tx.send(pkts);
}
}).unwrap();

let pkts = rx.recv().unwrap();
println!("receiving {} packets...", pkts);
for _ in 0..pkts {
let mut buf: [u8; 1514] = [0; 1514];
println!("{:?}", iface.read(&mut buf));
let shared_mode = Shared {
subnet_options: None,
..Default::default()
};

let mut iface = Interface::new(Mode::Shared(shared_mode), Options::default()).unwrap();

let (tx, rx) = sync::mpsc::sync_channel(0);

iface.set_event_callback(Events::PACKETS_AVAILABLE, move |events, params| {
if let Some(Parameter::EstimatedPacketsAvailable(pkts)) = params.get(ParameterKind::EstimatedPacketsAvailable) {
tx.send(pkts);
}
}).unwrap();

drop(rx);
iface.finalize().unwrap();
let pkts = rx.recv().unwrap();
println!("receiving {} packets...", pkts);
for _ in 0..pkts {
let mut buf: [u8; 1514] = [0; 1514];
println!("{:?}", iface.read(&mut buf));
}

drop(rx);
iface.finalize().unwrap();
```

## Quirks and missing functionality
Expand Down

0 comments on commit 2c02c25

Please sign in to comment.