Skip to content

Commit

Permalink
Merge #1677
Browse files Browse the repository at this point in the history
1677: Use the same signature for LinkAddr::addr on all platforms r=rtzoeller a=asomers

This should've been done as part of #1675

Co-authored-by: Alan Somers <asomers@gmail.com>
  • Loading branch information
bors[bot] and asomers committed Mar 14, 2022
2 parents 9e63cb7 + d97e292 commit 445a438
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
(#[1642](https://github.com/nix-rust/nix/pull/1642))
- Fixed a panic in `LinkAddr::addr`. That function now returns an `Option`.
(#[1675](https://github.com/nix-rust/nix/pull/1675))
(#[1677](https://github.com/nix-rust/nix/pull/1677))

### Removed

Expand Down
26 changes: 15 additions & 11 deletions src/sys/socket/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1351,28 +1351,32 @@ mod datalink {
}

/// Physical-layer address (MAC)
pub fn addr(&self) -> [u8; 6] {
[
// Returns an Option just for cross-platform compatibility
pub fn addr(&self) -> Option<[u8; 6]> {
Some([
self.0.sll_addr[0] as u8,
self.0.sll_addr[1] as u8,
self.0.sll_addr[2] as u8,
self.0.sll_addr[3] as u8,
self.0.sll_addr[4] as u8,
self.0.sll_addr[5] as u8,
]
])
}
}

impl fmt::Display for LinkAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let addr = self.addr();
write!(f, "{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}",
addr[0],
addr[1],
addr[2],
addr[3],
addr[4],
addr[5])
if let Some(addr) = self.addr() {
write!(f, "{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}",
addr[0],
addr[1],
addr[2],
addr[3],
addr[4],
addr[5])
} else {
Ok(())
}
}
}
}
Expand Down

0 comments on commit 445a438

Please sign in to comment.