naccyde / rpms / systemd

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