Skip to content

Commit 9eabdf0

Browse files
committed
Add routing socket type on macOS
1 parent fbebb21 commit 9eabdf0

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/sys/socket/addr.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ pub enum AddressFamily {
8181
#[cfg(any(target_os = "android", target_os = "linux"))]
8282
#[cfg_attr(docsrs, doc(cfg(all())))]
8383
Netlink = libc::AF_NETLINK,
84+
/// Kernel interface for interacting with the routing table
85+
#[cfg(target_os = "macos")]
86+
Route = libc::PF_ROUTE,
8487
/// Low level packet interface (see [`packet(7)`](https://man7.org/linux/man-pages/man7/packet.7.html))
8588
#[cfg(any(
8689
target_os = "android",
@@ -422,6 +425,8 @@ impl AddressFamily {
422425
libc::AF_NETLINK => Some(AddressFamily::Netlink),
423426
#[cfg(any(target_os = "macos", target_os = "macos"))]
424427
libc::AF_SYSTEM => Some(AddressFamily::System),
428+
#[cfg(target_os = "macos")]
429+
libc::PF_ROUTE => Some(AddressFamily::Route),
425430
#[cfg(any(target_os = "android", target_os = "linux"))]
426431
libc::AF_PACKET => Some(AddressFamily::Packet),
427432
#[cfg(any(

src/sys/socket/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,4 +2462,16 @@ mod tests {
24622462
fn can_use_cmsg_space() {
24632463
let _ = cmsg_space!(u8);
24642464
}
2465+
2466+
#[cfg(target_os = "macos")]
2467+
#[test]
2468+
fn can_open_routing_socket() {
2469+
let _ = super::socket(
2470+
super::AddressFamily::Route,
2471+
super::SockType::Raw,
2472+
super::SockFlag::empty(),
2473+
None,
2474+
)
2475+
.expect("Failed to open routing socket");
2476+
}
24652477
}

0 commit comments

Comments
 (0)