From: Chuck Lever Date: Thu, 14 Jan 2010 17:22:42 +0000 (-0500) Subject: sm-notify: IPv6 support in reserved port binding in smn_create_socket() X-Git-Tag: nfs-utils-1-2-2-rc7~19 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=86cfdf1d38da18f9f917c674daba79a4435445a7;p=nfs-utils.git sm-notify: IPv6 support in reserved port binding in smn_create_socket() This patch updates the "bind to an arbitrary privileged port" arm of smn_create_socket() so it can deal with IPv6 bind addresses. Signed-off-by: Chuck Lever --- diff --git a/utils/statd/sm-notify.c b/utils/statd/sm-notify.c index 0ba817a..928d1c5 100644 --- a/utils/statd/sm-notify.c +++ b/utils/statd/sm-notify.c @@ -215,6 +215,26 @@ static int smn_socket(void) } #endif /* !IPV6_SUPPORTED */ +#ifdef HAVE_LIBTIRPC +static int +smn_bindresvport(int sock, struct sockaddr *sap) +{ + return bindresvport_sa(sock, sap); +} + +#else /* !HAVE_LIBTIRPC */ +static int +smn_bindresvport(int sock, struct sockaddr *sap) +{ + if (sap->sa_family != AF_INET) { + errno = EAFNOSUPPORT; + return -1; + } + + return bindresvport(sock, (struct sockaddr_in *)(char *)sap); +} +#endif /* !HAVE_LIBTIRPC */ + /* * Prepare a socket for sending RPC requests * @@ -265,7 +285,14 @@ retry: } else { struct servent *se; struct sockaddr_in *sin = (struct sockaddr_in *)local_addr; - (void) bindresvport(sock, sin); + + if (smn_bindresvport(sock, local_addr) == -1) { + xlog(L_ERROR, + "bindresvport on RPC socket failed: %m"); + (void)close(sock); + return -1; + } + /* try to avoid known ports */ se = getservbyport(sin->sin_port, "udp"); if (se && retry_cnt < 100) {