NetBSD: HOST_NAME_MAX Not Defined #2

Closed
opened 2023-09-05 19:56:42 +00:00 by jordan · 2 comments
Owner

Building on NetBSD fails because HOST_NAME_MAX is not defined. We need to figure out if HOST_NAME_MAX is POSIX or not, and if it is, then how to enable its visibility on NetBSD.

Building on NetBSD fails because HOST_NAME_MAX is not defined. We need to figure out if HOST_NAME_MAX is POSIX or not, and if it is, then how to enable its visibility on NetBSD.
jordan added the
bug
label 2023-09-05 19:56:42 +00:00
jordan added this to the (deleted) milestone 2023-09-05 20:16:57 +00:00
jordan added this to the Telodendria v1.7.0-alpha4 project 2023-09-05 20:18:04 +00:00
jordan self-assigned this 2023-09-06 02:01:20 +00:00
Contributor

Just looked up about the HOST_NAME_MAX, and if GNU's manuals are to be believed, all of these platforms(versions included) don't have it defined(so it's not merely a NetBSD-specific issue):

The HOST_NAME_MAX macro is not defined on some platforms: macOS 11.1, FreeBSD 13.0, NetBSD 9.0, OpenBSD 6.7, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 11.4, Cygwin 1.5.x, mingw, MSVC 14.

Just looked up about the HOST_NAME_MAX, and if GNU's manuals are to be believed, all of these platforms(versions included) don't have it defined(so it's not merely a NetBSD-specific issue): > The HOST_NAME_MAX macro is not defined on some platforms: macOS 11.1, FreeBSD 13.0, NetBSD 9.0, OpenBSD 6.7, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 11.4, Cygwin 1.5.x, mingw, MSVC 14. * https://www.gnu.org/software/gnulib/manual/html_node/limits_002eh.html
Author
Owner

Interesting. Let's take a look at the official POSIX standard: https://bancino.net/mirror/susv4-2018/basedefs/limits.h.html. It appears that HOST_NAME_MAX is a runtime invariant that may be omitted:

Runtime Invariant Values (Possibly Indeterminate)

A definition of one of the symbolic constants in the following list shall be omitted from <limits.h> on specific implementations where the corresponding value is equal to or greater than the stated minimum, but is unspecified.

This indetermination might depend on the amount of available memory space on a specific instance of a specific implementation. The actual value supported by a specific instance shall be provided by the sysconf() function.

...

{HOST_NAME_MAX}

Maximum length of a host name (not including the terminating null) as returned from the gethostname() function.
Minimum Acceptable Value: {_POSIX_HOST_NAME_MAX}

So, at first glance, it looks like we need to use sysconf() to get the actual value if we want it. Otherwise, it looks like _POSIX_HOST_NAME_MAX is required to be defined:

Minimum Values

The <limits.h> header shall define the following symbolic constants with the values shown. These are the most restrictive values for certain features on an implementation conforming to this volume of POSIX.1-2017. Related symbolic constants are defined elsewhere in this volume of POSIX.1-2017 which reflect the actual implementation and which need not be as restrictive. For each of these limits, a conforming implementation shall provide a value at least this large or shall have no limit. A strictly conforming application must not require a larger value for correct operation.

...

{_POSIX_HOST_NAME_MAX}
Maximum length of a host name (not including the terminating null) as returned from the gethostname() function.

In that case, this simple code should theoretically work:

#ifndef HOST_NAME_MAX
#define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
#endif

Although I haven't tested it. We'll want to patch this into the file that uses HOST_NAME_MAX. Otherwise, if it is used in multiple places, we may want to add it to a different (possibly new) header.

Interesting. Let's take a look at the official POSIX standard: https://bancino.net/mirror/susv4-2018/basedefs/limits.h.html. It appears that `HOST_NAME_MAX` is a runtime invariant that may be omitted: > ## Runtime Invariant Values (Possibly Indeterminate) > > A definition of one of the symbolic constants in the following list shall be omitted from <limits.h> on specific implementations where the corresponding value is equal to or greater than the stated minimum, but is unspecified. > > This indetermination might depend on the amount of available memory space on a specific instance of a specific implementation. The actual value supported by a specific instance shall be provided by the sysconf() function. > > ... > > {HOST_NAME_MAX} >> Maximum length of a host name (not including the terminating null) as returned from the gethostname() function. >> Minimum Acceptable Value: {_POSIX_HOST_NAME_MAX} So, at first glance, it looks like we need to use `sysconf()` to get the actual value if we want it. Otherwise, it looks like `_POSIX_HOST_NAME_MAX` *is* required to be defined: > ## Minimum Values > > The <limits.h> header shall define the following symbolic constants with the values shown. These are the most restrictive values for certain features on an implementation conforming to this volume of POSIX.1-2017. Related symbolic constants are defined elsewhere in this volume of POSIX.1-2017 which reflect the actual implementation and which need not be as restrictive. For each of these limits, a conforming implementation shall provide a value at least this large or shall have no limit. A strictly conforming application must not require a larger value for correct operation. > > ... > > {_POSIX_HOST_NAME_MAX} > Maximum length of a host name (not including the terminating null) as returned from the gethostname() function. In that case, this simple code should *theoretically* work: ```c #ifndef HOST_NAME_MAX #define HOST_NAME_MAX _POSIX_HOST_NAME_MAX #endif ``` Although I haven't tested it. We'll want to patch this into the file that uses `HOST_NAME_MAX`. Otherwise, if it is used in multiple places, we may want to add it to a different (possibly new) header.
Sign in to join this conversation.
No milestone
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Telodendria/Telodendria#2
No description provided.