Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ authors = ["dlevy47 <dlevy47>"]
license = "mit"

[dependencies]
nix = "*"
libc = "*"
nix = "0.9.0"
libc = "0.2.32"

[[bin]]
path = "src/bin/ifaces.rs"
Expand Down
25 changes: 9 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,18 @@ This library contains functionality to retrieve network interface information on

See `src/bin/ifaces.rs` for an example of printing out network interfaces on a machine:

```rust
extern crate "rust-ifaces" as ifaces;

fn main () {
for iface in
ifaces::Interface::get_all().unwrap()
.into_iter()
.filter(|x| x.kind == ifaces::Kind::Packet) {
println!("{}", iface.name);
}
}
```bash
cargo run --bin ifaces
```

On my machine, this prints out:

```
$ target/ifaces
lo
eth0
wlan0
docker0
Interface { name: "lo0", kind: Ipv4, addr: Some(V4(127.0.0.1:0)), mask: Some(V4(255.0.0.0:0)), hop: Some(Destination(V4(127.0.0.1:0))) }
Interface { name: "lo0", kind: Ipv6, addr: Some(V6([::]:0)), mask: Some(V6([ff:ff:ff:ff:ff:ff:ff:ff]:0)), hop: Some(Destination(V6([::]:0))) }
Interface { name: "lo0", kind: Ipv6, addr: Some(V6([fe:80::]:0)), mask: Some(V6([ff:ff:ff:ff:ff:ff:ff:ff]:0)), hop: None }
Interface { name: "en0", kind: Ipv6, addr: Some(V6([fe:80::]:0)), mask: Some(V6([ff:ff:ff:ff:ff:ff:ff:ff]:0)), hop: None }
Interface { name: "en0", kind: Ipv4, addr: Some(V4(192.168.0.101:0)), mask: Some(V4(255.255.255.0:0)), hop: Some(Broadcast(V4(192.168.0.255:0))) }
Interface { name: "awdl0", kind: Ipv6, addr: Some(V6([fe:80::]:0)), mask: Some(V6([ff:ff:ff:ff:ff:ff:ff:ff]:0)), hop: None }
Interface { name: "utun0", kind: Ipv6, addr: Some(V6([fe:80::]:0)), mask: Some(V6([ff:ff:ff:ff:ff:ff:ff:ff]:0)), hop: None }
```
12 changes: 6 additions & 6 deletions src/bin/ifaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ extern crate ifaces;

#[cfg(not(test))]
fn main () {
for iface in
ifaces::Interface::get_all().unwrap()
.into_iter()
.filter(|x| x.kind == ifaces::Kind::Packet) {
println!("{}", iface.name);
}
let ifaces = ifaces::Interface::get_all().unwrap()
.into_iter()
.filter(|x| x.kind != ifaces::Kind::Packet);
for iface in ifaces {
println!("{:?}", iface);
}
}
18 changes: 9 additions & 9 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::net::IpAddr;
// nix doesn't have this const
pub const AF_PACKET: i32 = 17;

#[allow(dead_code)]
#[allow(dead_code, non_camel_case_types)]
#[repr(C)]
pub enum SIOCGIFFLAGS {
IFF_UP = 0x1, /* Interface is up. */
Expand Down Expand Up @@ -86,14 +86,14 @@ pub fn convert_sockaddr (sa: *mut socket::sockaddr) -> Option<net::SocketAddr> {
let (addr, port) = (sa.sin6_addr.s6_addr, sa.sin6_port);
(
IpAddr::V6(net::Ipv6Addr::new(
addr[0],
addr[1],
addr[2],
addr[3],
addr[4],
addr[5],
addr[6],
addr[7],
addr[0] as u16,
addr[1] as u16,
addr[2] as u16,
addr[3] as u16,
addr[4] as u16,
addr[5] as u16,
addr[6] as u16,
addr[7] as u16,
)),
port
)
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(ip_addr)]

extern crate libc;
extern crate nix;

Expand Down