]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
getport: replace getnameinfo(NI_NUMERICHOST) with inet_ntop(3)
authorChuck Lever <chuck.lever@oracle.com>
Tue, 14 Jul 2009 20:12:23 +0000 (16:12 -0400)
committerSteve Dickson <steved@redhat.com>
Tue, 14 Jul 2009 20:12:23 +0000 (16:12 -0400)
getnameinfo(3) with the NI_NUMERICHOST flag is used in
support/nfs/getport.c to convert socket addresses to universal address
strings.

Older versions of glibc do not have getnameinfo(3), however.  In order
for nfs-utils to build on older systems we switch in legacy code via
HAVE_GETNAMEINFO and use inet_ntoa(3).

A problem with this is that we have to double our test matrix to be
sure that both versions of these routines build and operate correctly.
Another minor problem is that inet_ntoa(3) is officially deprecated.

So let's always use a single implementation based on inet_ntop(3).
Universal address strings do not support link-local / scope IDs, so we
don't lose any functionality by using inet_ntop(3) here.

This means we open code a bit of logic that is available in most
modern versions of glibc, but in return we can use exactly the same
code for all builds (on systems with getnameinfo(3) and without).

An additional benefit is we can avoid using NI_MAXHOST for character
buffers that live on the stack: it's 1025 bytes.  Instead,
INET6_ADDRSTRLEN is used, which is just 46 bytes, plus an additional
eight bytes for the port information.  We add beefier buffer overflow
detection logic as well.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Steve Dickson <steved@redhat.com>

No differences found