chiark / gitweb /
sd-daemon: use sockaddr_port() helper
authorLennart Poettering <lennart@poettering.net>
Tue, 26 Dec 2017 12:36:07 +0000 (13:36 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:49:45 +0000 (07:49 +0200)
src/libelogind/sd-daemon/sd-daemon.c

index 7aad70bc6cbcdac9706aceb67d7886ae56493a72..3e4c19cf538804450ec0e357831771ac016a7cc3 100644 (file)
@@ -309,17 +309,13 @@ _public_ int sd_is_socket_inet(int fd, int family, int type, int listening, uint
                         return 0;
 
         if (port > 0) {
-                if (sockaddr.sa.sa_family == AF_INET) {
-                        if (l < sizeof(struct sockaddr_in))
-                                return -EINVAL;
+                unsigned sa_port;
 
-                        return htobe16(port) == sockaddr.in.sin_port;
-                } else {
-                        if (l < sizeof(struct sockaddr_in6))
-                                return -EINVAL;
+                r = sockaddr_port(&sockaddr.sa, &sa_port);
+                if (r < 0)
+                        return r;
 
-                        return htobe16(port) == sockaddr.in6.sin6_port;
-                }
+                return port == sa_port;
         }
 
         return 1;