blob: 37c6bfe7d35021df259622c6a86c3ffe00fbd943 [file]
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#![deny(warnings)]
use std::net::UdpSocket;
use structopt::StructOpt;
#[derive(StructOpt, Debug)]
struct Transfer {
send_byte: u8,
receive_byte: u8,
length: usize,
}
fn main() -> std::io::Result<()> {
match Transfer::from_args() {
Transfer {
send_byte,
receive_byte,
length,
} => {
// Bind the socket to all addresses, on port 4242.
let socket = UdpSocket::bind(("0.0.0.0", 4242))?;
// Send to 192.168.0.1, the IPv4 address of the host.
let send_buf = vec![send_byte; length];
socket.send_to(&send_buf, ("192.168.0.1", 4242))?;
let mut recv_buf = vec![0; length];
let actual = socket.recv(&mut recv_buf)?;
if actual == length && recv_buf.iter().all(|b| *b == receive_byte) {
println!("PASS");
}
}
}
Ok(())
}