richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
803fb7
From 73cbcbaf7e04d42816ada8ee44b5fbc6b7f0bdb4 Mon Sep 17 00:00:00 2001
803fb7
From: Michal Schmidt <mschmidt@redhat.com>
803fb7
Date: Fri, 20 Feb 2015 02:04:05 +0100
803fb7
Subject: [PATCH] shared: use SocketAddress in socket_address_matches_fd()
803fb7
803fb7
Cleanup. No behavior change.
803fb7
803fb7
(cherry picked from commit dbafedacba3ee77098e932222ae7840e7b4040fc)
803fb7
---
803fb7
 src/shared/socket-util.c | 36 ++++++++++++++++++------------------
803fb7
 1 file changed, 18 insertions(+), 18 deletions(-)
803fb7
803fb7
diff --git a/src/shared/socket-util.c b/src/shared/socket-util.c
803fb7
index c278d6f9d..c31f60ec7 100644
803fb7
--- a/src/shared/socket-util.c
803fb7
+++ b/src/shared/socket-util.c
803fb7
@@ -435,48 +435,48 @@ bool socket_ipv6_is_supported(void) {
803fb7
 }
803fb7
 
803fb7
 bool socket_address_matches_fd(const SocketAddress *a, int fd) {
803fb7
-        union sockaddr_union sa;
803fb7
-        socklen_t salen = sizeof(sa), solen;
803fb7
-        int protocol, type;
803fb7
+        SocketAddress b;
803fb7
+        socklen_t solen;
803fb7
 
803fb7
         assert(a);
803fb7
         assert(fd >= 0);
803fb7
 
803fb7
-        if (getsockname(fd, &sa.sa, &salen) < 0)
803fb7
+        b.size = sizeof(b.sockaddr);
803fb7
+        if (getsockname(fd, &b.sockaddr.sa, &b.size) < 0)
803fb7
                 return false;
803fb7
 
803fb7
-        if (sa.sa.sa_family != a->sockaddr.sa.sa_family)
803fb7
+        if (b.sockaddr.sa.sa_family != a->sockaddr.sa.sa_family)
803fb7
                 return false;
803fb7
 
803fb7
-        solen = sizeof(type);
803fb7
-        if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &type, &solen) < 0)
803fb7
+        solen = sizeof(b.type);
803fb7
+        if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &b.type, &solen) < 0)
803fb7
                 return false;
803fb7
 
803fb7
-        if (type != a->type)
803fb7
+        if (b.type != a->type)
803fb7
                 return false;
803fb7
 
803fb7
         if (a->protocol != 0)  {
803fb7
-                solen = sizeof(protocol);
803fb7
-                if (getsockopt(fd, SOL_SOCKET, SO_PROTOCOL, &protocol, &solen) < 0)
803fb7
+                solen = sizeof(b.protocol);
803fb7
+                if (getsockopt(fd, SOL_SOCKET, SO_PROTOCOL, &b.protocol, &solen) < 0)
803fb7
                         return false;
803fb7
 
803fb7
-                if (protocol != a->protocol)
803fb7
+                if (b.protocol != a->protocol)
803fb7
                         return false;
803fb7
         }
803fb7
 
803fb7
-        switch (sa.sa.sa_family) {
803fb7
+        switch (b.sockaddr.sa.sa_family) {
803fb7
 
803fb7
         case AF_INET:
803fb7
-                return sa.in.sin_port == a->sockaddr.in.sin_port &&
803fb7
-                        sa.in.sin_addr.s_addr == a->sockaddr.in.sin_addr.s_addr;
803fb7
+                return b.sockaddr.in.sin_port == a->sockaddr.in.sin_port &&
803fb7
+                        b.sockaddr.in.sin_addr.s_addr == a->sockaddr.in.sin_addr.s_addr;
803fb7
 
803fb7
         case AF_INET6:
803fb7
-                return sa.in6.sin6_port == a->sockaddr.in6.sin6_port &&
803fb7
-                        memcmp(&sa.in6.sin6_addr, &a->sockaddr.in6.sin6_addr, sizeof(struct in6_addr)) == 0;
803fb7
+                return b.sockaddr.in6.sin6_port == a->sockaddr.in6.sin6_port &&
803fb7
+                        memcmp(&b.sockaddr.in6.sin6_addr, &a->sockaddr.in6.sin6_addr, sizeof(struct in6_addr)) == 0;
803fb7
 
803fb7
         case AF_UNIX:
803fb7
-                return salen == a->size &&
803fb7
-                        memcmp(sa.un.sun_path, a->sockaddr.un.sun_path, salen - offsetof(struct sockaddr_un, sun_path)) == 0;
803fb7
+                return b.sockaddr.size == a->size &&
803fb7
+                        memcmp(b.sockaddr.un.sun_path, a->sockaddr.un.sun_path, b.size - offsetof(struct sockaddr_un, sun_path)) == 0;
803fb7
 
803fb7
         }
803fb7