krb5 commit: Use sa_is_wildcard() in libapputils

Greg Hudson ghudson at mit.edu
Mon Jan 9 11:25:00 EST 2017


https://github.com/krb5/krb5/commit/5fd71a54282140290473c876c28621b1c0e33148
commit 5fd71a54282140290473c876c28621b1c0e33148
Author: Greg Hudson <ghudson at mit.edu>
Date:   Mon Dec 26 18:56:06 2016 -0500

    Use sa_is_wildcard() in libapputils

 src/lib/apputils/net-server.c |   13 +------------
 src/lib/apputils/udppktinfo.c |   12 +++++-------
 2 files changed, 6 insertions(+), 19 deletions(-)

diff --git a/src/lib/apputils/net-server.c b/src/lib/apputils/net-server.c
index 29ec84a..92192d2 100644
--- a/src/lib/apputils/net-server.c
+++ b/src/lib/apputils/net-server.c
@@ -105,17 +105,6 @@ paddr(struct sockaddr *sa)
     return buf;
 }
 
-/* Return true if sa is an IPv4 or IPv6 wildcard address. */
-static int
-is_wildcard(struct sockaddr *sa)
-{
-    if (sa->sa_family == AF_INET6)
-        return IN6_IS_ADDR_UNSPECIFIED(&sa2sin6(sa)->sin6_addr);
-    else if (sa->sa_family == AF_INET)
-        return sa2sin(sa)->sin_addr.s_addr == INADDR_ANY;
-    return 0;
-}
-
 /* KDC data.  */
 
 enum conn_type {
@@ -764,7 +753,7 @@ setup_socket(struct socksetup *data, struct bind_address *ba,
     }
 
     /* Try to turn on pktinfo for UDP wildcard sockets. */
-    if (ba->type == UDP && is_wildcard(sock_address)) {
+    if (ba->type == UDP && sa_is_wildcard(sock_address)) {
         krb5_klog_syslog(LOG_DEBUG, _("Setting pktinfo on socket %s"),
                          paddr(sock_address));
         ret = set_pktinfo(sock, sock_address->sa_family);
diff --git a/src/lib/apputils/udppktinfo.c b/src/lib/apputils/udppktinfo.c
index bc7ad09..9e48b47 100644
--- a/src/lib/apputils/udppktinfo.c
+++ b/src/lib/apputils/udppktinfo.c
@@ -141,19 +141,17 @@ is_socket_bound_to_wildcard(int sock)
 {
     struct sockaddr_storage bound_addr;
     socklen_t bound_addr_len = sizeof(bound_addr);
+    struct sockaddr *sa = ss2sa(&bound_addr);
 
-    if (getsockname(sock, ss2sa(&bound_addr), &bound_addr_len) < 0)
+    if (getsockname(sock, sa, &bound_addr_len) < 0)
         return -1;
 
-    switch (ss2sa(&bound_addr)->sa_family) {
-    case AF_INET:
-        return ss2sin(&bound_addr)->sin_addr.s_addr == INADDR_ANY;
-    case AF_INET6:
-        return IN6_IS_ADDR_UNSPECIFIED(&ss2sin6(&bound_addr)->sin6_addr);
-    default:
+    if (!sa_is_inet(sa)) {
         errno = EINVAL;
         return -1;
     }
+
+    return sa_is_wildcard(sa);
 }
 
 #ifdef HAVE_IP_PKTINFO


More information about the cvs-krb5 mailing list