What is the maximum number of characters for a host-name in Unix?

后端 未结 6 677
余生分开走
余生分开走 2020-12-13 03:43

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

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-13 04:13

    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 to HOST_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 terminating NUL.

提交回复
热议问题