summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-03-14 13:05:45 +0000
committerGitHub <noreply@github.com>2022-03-14 13:05:45 +0000
commit445a4387ada6e71e226aaf9d6087174bd5102843 (patch)
tree4a04ecd2b4957eaf08440f372815f9b4f3a0815d
parent9e63cb732384c6039c369db85cfbbd45a2ddd5e9 (diff)
parentd97e292a5da5cb74f7a7c901e882fca022c387a4 (diff)
downloadnix-445a4387ada6e71e226aaf9d6087174bd5102843.zip
Merge #1677
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>
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/sys/socket/addr.rs26
2 files changed, 16 insertions, 11 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7f59926f..e54639b7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs
index 9fd9e30a..7803ec76 100644
--- a/src/sys/socket/addr.rs
+++ b/src/sys/socket/addr.rs
@@ -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(())
+ }
}
}
}