bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

netdb: Define NI_MAXHOST and NI_MAXSERV.


From: Collin Funk
Subject: netdb: Define NI_MAXHOST and NI_MAXSERV.
Date: Thu, 27 Jun 2024 01:30:25 -0700
User-agent: Gnus/5.13 (Gnus v5.13)

After Bruno mentioned the IPv4 limitation on inet_ntoa I decided to look
at modernizing Inetutils again. I also noticed gethostbyname,
gethostbyaddr were used which were obsoleted in POSIX 2001 and removed
in POSIX 2008.

Not too difficult to change to getaddrinfo and getnameinfo, but it means
choosing buffer sizes. When I grep through my sources it looks like
everyone uses NI_MAXHOST and NI_MAXSERV for this. Looking up these
macros you can find many instances of "missing definitions" though. This
is because the macros are only "standardized" in RFC 2553 [1]. On page
29 the following is listed:

    #define NI_MAXHOST  1025
    #define NI_MAXSERV    32

That is what glibc does too. I've applied the attached patches to make
sure these are defined correctly.

In order to document these I looked at some systems on the compile farm.
I noticed that on musl NI_MAXHOST is defined to 255 and on OpenBSD it is
256. For OpenBSD they say [2]:

    OpenBSD intentionally uses a different NI_MAXHOST value from what
    RFC 2553 suggests, to avoid buffer length handling mistakes.

My socket & networking knowledge isn't the best. Does anyone know why
RFC 2553 has the larger buffer size? I thought per RFC 1034 domain names
were limited to 253 bytes, with the trailing dot removed and empty root
label removed [3].

Collin

[1] https://datatracker.ietf.org/doc/html/rfc2553
[2] https://man.openbsd.org/getnameinfo.3
[3] https://datatracker.ietf.org/doc/html/rfc1034

Attachment: 0001-netdb-Define-NI_MAXHOST-and-NI_MAXSERV.patch
Description: Text Data

Attachment: 0002-netdb-tests-Check-for-NI_MAXHOST-and-NI_MAXSERV.patch
Description: Text Data

Attachment: 0003-doc-Fix-error-in-previous-commits.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]