Skip to content

Commit ed8319c

Browse files
Merge #1867
1867: Add routing socket type on macOS r=asomers a=pinkisemils This is a small change to add the routing socket type to the list of socket types one can open with `nix`. I've added a smoke test to see that a socket of such type can actually be opened, but I'm not sure if such a test belongs in the codebase here. Co-authored-by: Emils <[email protected]>
2 parents f263f45 + d08d4e2 commit ed8319c

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ This project adheres to [Semantic Versioning](https://semver.org/).
55

66
## [Unreleased] - ReleaseDate
77
### Added
8+
- Add `PF_ROUTE` to `SockType` on macOS, iOS, all of the BSDs, Fuchsia, Haiku, Illumos.
9+
([#1867](https://github.com/nix-rust/nix/pull/1867))
10+
811
### Changed
912
### Fixed
1013
### Removed

src/sys/socket/addr.rs

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

src/sys/socket/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,4 +2484,16 @@ mod tests {
24842484
fn can_use_cmsg_space() {
24852485
let _ = cmsg_space!(u8);
24862486
}
2487+
2488+
#[cfg(not(any(target_os = "redox", target_os = "linux", target_os = "android")))]
2489+
#[test]
2490+
fn can_open_routing_socket() {
2491+
let _ = super::socket(
2492+
super::AddressFamily::Route,
2493+
super::SockType::Raw,
2494+
super::SockFlag::empty(),
2495+
None,
2496+
)
2497+
.expect("Failed to open routing socket");
2498+
}
24872499
}

0 commit comments

Comments
 (0)