teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0047-shared-use-SocketAddress-in-socket_address_matches_f.patch

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