MCPcopy Create free account
hub / github.com/bendudson/EuraliOS / configure

Function configure

tcp/src/dhcp.rs:17–55  ·  view source on GitHub ↗

DHCP configuration on given interface Based on

(interface: &mut Interface)

Source from the content-addressed store, hash-verified

15///
16/// Based on <https://github.com/vinc/moros/blob/trunk/src/usr/dhcp.rs>
17pub fn configure(interface: &mut Interface) {
18
19 let dhcp_socket = Dhcpv4Socket::new();
20 let dhcp_handle = interface.add_socket(dhcp_socket);
21
22 if let Err(e) = interface.poll(Instant::from_millis(0)) { // This transmits
23 panic!("[tcp] Network Error: {}", e);
24 }
25
26 loop {
27 let event = interface.get_socket::<Dhcpv4Socket>(dhcp_handle).poll();
28 match event {
29 None => {}
30 Some(Dhcpv4Event::Configured(config)) => {
31 interface.remove_socket(dhcp_handle);
32
33 print!("[tcp] DHCP: IP {}", config.address);
34 set_ipv4_addr(interface, config.address);
35
36 if let Some(router) = config.router {
37 print!(" Router {}", router);
38 interface.routes_mut().add_default_ipv4_route(router).unwrap();
39 }
40
41 for addr in config.dns_servers.iter()
42 .filter(|addr| addr.is_some()).map(|addr| addr.unwrap()) {
43 print!(" DNS {}", addr);
44 dns::add_server(IpAddress::from(addr));
45 }
46 println!("");
47 break;
48 }
49 Some(Dhcpv4Event::Deconfigured) => {
50 }
51 }
52 // Wait and retry
53 syscalls::thread_yield();
54 }
55}
56
57/// Set the IPv4 address of an interface
58///

Callers 1

mainFunction · 0.85

Calls 4

set_ipv4_addrFunction · 0.85
add_serverFunction · 0.85
thread_yieldFunction · 0.85
iterMethod · 0.80

Tested by

no test coverage detected