Skip to content

Commit ab485fc

Browse files
committed
fix: Add FreeBSD compatibility for TCP socket options
Replace Linux-only SOL_TCP with IPPROTO_TCP for FreeBSD Add OS-specific TCP option constants (TCP_KEEPIDLE, TCP_KEEPINTVL, TCP_KEEPCNT) Add missing imports: std::iter::repeat, libc::c_void Wrap setsockopt / getsockopt calls for cross-platform compatibility
1 parent fb11a14 commit ab485fc

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

bin/src/util.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,11 @@ pub fn get_config_file_path(args: &cli::Args) -> Result<&str, UtilError> {
118118

119119
#[cfg(target_os = "freebsd")]
120120
pub unsafe fn get_executable_path() -> Result<String, UtilError> {
121+
use libc::{CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, PATH_MAX};
122+
use libc::{c_void, sysctl};
123+
121124
let mut capacity = PATH_MAX as usize;
122-
let mut path: Vec<u8> = Vec::with_capacity(capacity);
123-
path.extend(repeat(0).take(capacity));
125+
let mut path = vec![0; capacity];
124126

125127
let mib: Vec<i32> = vec![CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1];
126128
let len = mib.len() * size_of::<i32>();

lib/src/socket.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,17 @@ pub mod stats {
534534
#[cfg(unix)]
535535
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
536536
mod internal {
537+
#[cfg(target_os = "linux")]
537538
pub const OPT_LEVEL: libc::c_int = libc::SOL_TCP;
539+
540+
#[cfg(any(
541+
target_os = "freebsd",
542+
target_os = "dragonfly",
543+
target_os = "openbsd",
544+
target_os = "netbsd"
545+
))]
546+
pub const OPT_LEVEL: libc::c_int = libc::IPPROTO_TCP;
547+
538548
pub const OPT_NAME: libc::c_int = libc::TCP_INFO;
539549

540550
#[derive(Clone, Debug)]

0 commit comments

Comments
 (0)