|
| 1 | +// socketcan/examples/enumerate.rs |
| 2 | +// |
| 3 | +// Example application for listing available SocketCAN interfaces |
| 4 | +// |
| 5 | +// This file is part of the Rust 'socketcan-rs' library. |
| 6 | +// |
| 7 | +// Licensed under the MIT license: |
| 8 | +// <LICENSE or http://opensource.org/licenses/MIT> |
| 9 | +// This file may not be copied, modified, or distributed except according |
| 10 | +// to those terms. |
| 11 | + |
| 12 | +//! An example that lists available SocketCAN interfaces. |
| 13 | +
|
| 14 | +use socketcan::available_interfaces; |
| 15 | + |
| 16 | +fnmain(){ |
| 17 | +matchavailable_interfaces(){ |
| 18 | +Ok(interfaces) =>{ |
| 19 | +match interfaces.len(){ |
| 20 | +0 =>println!("No CAN interfaces found."), |
| 21 | +1 =>println!("Found 1 CAN interface:"), |
| 22 | + n =>println!("Found {} CAN interfaces:", n), |
| 23 | +}; |
| 24 | + |
| 25 | +for ifacein interfaces{ |
| 26 | +println!("{}", iface); |
| 27 | +} |
| 28 | +} |
| 29 | +Err(e) =>{ |
| 30 | +eprintln!("{:?}", e); |
| 31 | +eprintln!("Error listing CAN interfaces") |
| 32 | +} |
| 33 | +} |
| 34 | +} |