I am wondering what is the maximum number of characters for a host-name in a Unix system. In addition is there any defined variable that can be used in Unix programming to c
Git 2.13 (Q2 2017) illustrates that name length limit in C, and reminds that POSIX does not specify whether the buffer will be null-terminated.
It introduces a new function, xgethostname()
, which ensures that there is always a \0
at the end of the buffer.
See commit 5781a9a (18 Apr 2017) by David Turner (csusbdt).
(Merged by David Turner -- csusbdt -- in commit 5781a9a, 19 Apr 2017)
use
HOST_NAME_MAX
to size buffers for gethostname(2)
POSIX
limits the length of host names toHOST_NAME_MAX
.
Export the fallback definition from daemon.c and use this constant to make all buffers used with gethostname(2) big enough for any possible result and a terminatingNUL
.