Skip to content

Commit 445a438

Browse files
bors[bot]asomers
andauthored
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 <[email protected]>
2 parents 9e63cb7 + d97e292 commit 445a438

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
8181
(#[1642](https://github.com/nix-rust/nix/pull/1642))
8282
- Fixed a panic in `LinkAddr::addr`. That function now returns an `Option`.
8383
(#[1675](https://github.com/nix-rust/nix/pull/1675))
84+
(#[1677](https://github.com/nix-rust/nix/pull/1677))
8485

8586
### Removed
8687

src/sys/socket/addr.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -1351,28 +1351,32 @@ mod datalink {
13511351
}
13521352

13531353
/// Physical-layer address (MAC)
1354-
pub fn addr(&self) -> [u8; 6] {
1355-
[
1354+
// Returns an Option just for cross-platform compatibility
1355+
pub fn addr(&self) -> Option<[u8; 6]> {
1356+
Some([
13561357
self.0.sll_addr[0] as u8,
13571358
self.0.sll_addr[1] as u8,
13581359
self.0.sll_addr[2] as u8,
13591360
self.0.sll_addr[3] as u8,
13601361
self.0.sll_addr[4] as u8,
13611362
self.0.sll_addr[5] as u8,
1362-
]
1363+
])
13631364
}
13641365
}
13651366

13661367
impl fmt::Display for LinkAddr {
13671368
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1368-
let addr = self.addr();
1369-
write!(f, "{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}",
1370-
addr[0],
1371-
addr[1],
1372-
addr[2],
1373-
addr[3],
1374-
addr[4],
1375-
addr[5])
1369+
if let Some(addr) = self.addr() {
1370+
write!(f, "{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}",
1371+
addr[0],
1372+
addr[1],
1373+
addr[2],
1374+
addr[3],
1375+
addr[4],
1376+
addr[5])
1377+
} else {
1378+
Ok(())
1379+
}
13761380
}
13771381
}
13781382
}

0 commit comments

Comments
 (0)