summaryrefslogtreecommitdiff
path: root/src/sys/socket
diff options
context:
space:
mode:
Diffstat (limited to 'src/sys/socket')
-rw-r--r--src/sys/socket/addr.rs26
1 files changed, 15 insertions, 11 deletions
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(())
+ }
}
}
}