Init repo
This commit is contained in:
50
src/main.rs
Normal file
50
src/main.rs
Normal file
@@ -0,0 +1,50 @@
|
||||
use dhcproto::{
|
||||
Encodable,
|
||||
Encoder,
|
||||
v6::{
|
||||
DhcpOption,
|
||||
Message,
|
||||
MessageType,
|
||||
OptionCode,
|
||||
ORO,
|
||||
},
|
||||
};
|
||||
use std::net::SocketAddrV6;
|
||||
use tokio::net::UdpSocket;
|
||||
|
||||
const scope_id: u32 = 15;
|
||||
const duid: [u8; 4] = [0x13, 0x37, 0x23, 0x42];
|
||||
|
||||
const All_DHCP_Relay_Agents_and_Servers: &str = "ff02::1:2";
|
||||
const DHCP_Client_port: u16 = 546;
|
||||
const DHCP_Relay_Agent_and_Server_port: u16 = 547;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let socket_addr = SocketAddrV6::new("::".parse().unwrap(), DHCP_Client_port, 0, scope_id);
|
||||
let sock = UdpSocket::bind(socket_addr).await.unwrap();
|
||||
|
||||
let remote_addr = SocketAddrV6::new(All_DHCP_Relay_Agents_and_Servers.parse().unwrap(), DHCP_Relay_Agent_and_Server_port, 0, scope_id);
|
||||
|
||||
let mut msg = Message::new(MessageType::InformationRequest);
|
||||
let mut msg_opts = msg.opts_mut();
|
||||
//msg_opts.insert(DhcpOption::ClientId(Vec::from(duid)));
|
||||
msg_opts.insert(DhcpOption::ElapsedTime(0));
|
||||
msg_opts.insert(DhcpOption::ORO(ORO { opts: vec![
|
||||
OptionCode::InfMaxRt,
|
||||
OptionCode::InformationRefreshTime,
|
||||
OptionCode::DomainNameServers,
|
||||
OptionCode::DomainSearchList,
|
||||
],})); // request options
|
||||
|
||||
let mut msg_buf = Vec::new();
|
||||
let mut msg_encoder = Encoder::new(&mut msg_buf);
|
||||
msg.encode(&mut msg_encoder).unwrap(); // Serializes msg to msg_buf
|
||||
|
||||
sock.send_to(&msg_buf, remote_addr).await.unwrap();
|
||||
|
||||
let mut buf = [0; 1024];
|
||||
let (len, recv_addr) = sock.recv_from(&mut buf).await.unwrap();
|
||||
println!("{:?} bytes received from {:?}", len, recv_addr);
|
||||
println!("{}", &buf[..len].escape_ascii().to_string());
|
||||
}
|
Reference in New Issue
Block a user