Host name limits
Neal H Walfield writes:
> Richard Kettlewell writes:
>> It would be better to use "sizeof stuff" instead of 1024 (since
>> stuff is an array in this case) and even better to avoid a fixed
>> limit on string size altogether (there are useful URLs out there
>> longer than 1023 characters).
>
> The better thing to do is not to use some arbirtary limit, but
> rather to use MAXHOSTNAMELEN.
The requirement is for a buffer for URLs, not merely for hostnames, so
this is poor advice.
> However, this constant, although defined by many operating systems,
> is not as portable as you may wish: it is not specified by either
> POSIX or the upcoming release of the third Single Unix
> Specification. Thus, when this constant is not defined, you must
> query the OS via `sysconf (_SC_HOST_NAME_MAX)' for the maximum
> hostname length. The operating system is, however, allowed to
> return -1 indicating that there is no limit. In this case, the
> portable thing to do is not to impose a random upper limit but do
> something like the following:
This is better advice, though I already suggested completely avoiding
a fixed limit, as you will notice above.
Incidentally do the GNU/Hurd developers imagine there will be
hostnames longer than 255 characters? It will never see any from the
DNS (RFC1035 2.3.4), and I doubt many people would have the patience
to type in hostnames even half that long.
ttfn/rjk
Reply to: