Attempting to acquire the value of the 'kern.hostname' ctl from a kext by calling sysctlbyname() returns EPERM with no hostname returned. sysctlbyname() is aliased to kernel_sysctlbyname():
config/Libkern.exports:839:_sysctlbyname:_kernel_sysctlbyname
Looking at the implementation of kernel_sysctlbyname(), EPERM is returned by sysctl_root(). Not sure how to correctly identify the point of failure.
Alternately, calling
sysctlbyname("hw.ncpu")
does return the value set for the ctl.
The kext was compiled with SYSCTL_DEF_ENABLED defined to have the relevant section of sys/sysctl.h enabled.
bsd_hostname() is a private symbol which is inaccessible to my kext.
% sysctl -n kern.hostname
does return the host name, so the ctl must be set.
Is it possible to get the name of a host from the context of my kext?
Thanks.