diff options
Diffstat (limited to 'crates/shirabe-php-shim/src/net.rs')
| -rw-r--r-- | crates/shirabe-php-shim/src/net.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/crates/shirabe-php-shim/src/net.rs b/crates/shirabe-php-shim/src/net.rs index 0ecf5cb..5632c83 100644 --- a/crates/shirabe-php-shim/src/net.rs +++ b/crates/shirabe-php-shim/src/net.rs @@ -1,7 +1,14 @@ use std::net::{IpAddr, SocketAddr, ToSocketAddrs}; pub fn gethostname() -> String { - todo!() + // PHP's gethostname() wraps gethostname(2). On Linux the kernel exposes the + // same value via /proc; fall back to the HOSTNAME env var, then to "localhost". + std::fs::read_to_string("/proc/sys/kernel/hostname") + .ok() + .map(|s| s.trim().to_string()) + .filter(|s| !s.is_empty()) + .or_else(|| std::env::var("HOSTNAME").ok().filter(|s| !s.is_empty())) + .unwrap_or_else(|| "localhost".to_string()) } // Resolves the first IPv4 address for the host name, mirroring PHP's gethostbyname |
