announce server hostname in MANIFEST, display in client
Server reads its hostname via gethostname(2) and includes it as a length-prefixed UTF-8 string at the start of the MANIFEST payload. Client displays 'Server: <hostname> — <MAC>' in a label above the upstream list. Both sides updated for the new MANIFEST format: [hostname_len:1][hostname:N][entries...] Protocol version unchanged (still 1); MANIFEST payload layout change is backward-incompatible but both sides ship together.
This commit is contained in:
+15
-1
@@ -1,6 +1,20 @@
|
||||
//! Upstream table: cmdline parsing and MANIFEST entry construction.
|
||||
|
||||
use crate::frame::{UpstreamEntry, PROTO_TCP, PROTO_UDP};
|
||||
use crate::frame::{Frame, UpstreamEntry, PROTO_TCP, PROTO_UDP};
|
||||
|
||||
/// Read the system hostname via `gethostname(2)`.
|
||||
pub fn get_hostname() -> String {
|
||||
let mut buf = [0u8; 256];
|
||||
let ret = unsafe {
|
||||
libc::gethostname(buf.as_mut_ptr() as *mut libc::c_char, buf.len())
|
||||
};
|
||||
if ret == 0 {
|
||||
let len = buf.iter().position(|&b| b == 0).unwrap_or(buf.len());
|
||||
String::from_utf8_lossy(&buf[..len]).into_owned()
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[allow(dead_code)]
|
||||
|
||||
Reference in New Issue
Block a user