[pulseaudio-commits] r2532 - in /trunk/src/pulsecore: socket-util.c socket-util.h

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Mon Jun 16 11:45:18 PDT 2008


Author: lennart
Date: Mon Jun 16 20:45:17 2008
New Revision: 2532

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=2532&root=pulseaudio&view=rev
Log:
add new functions pa_socket_is_local() and pa_socket_address_is_local()

Modified:
    trunk/src/pulsecore/socket-util.c
    trunk/src/pulsecore/socket-util.h

Modified: trunk/src/pulsecore/socket-util.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/socket-util.c?rev=2532&root=pulseaudio&r1=2531&r2=2532&view=diff
==============================================================================
--- trunk/src/pulsecore/socket-util.c (original)
+++ trunk/src/pulsecore/socket-util.c Mon Jun 16 20:45:17 2008
@@ -129,8 +129,8 @@
                 return;
 #endif
             }
-
         }
+
 #ifndef OS_IS_WIN32
         pa_snprintf(c, l, "Unknown network client");
         return;
@@ -284,3 +284,40 @@
 }
 
 #endif /* HAVE_SYS_UN_H */
+
+
+pa_bool_t pa_socket_address_is_local(const struct sockaddr *sa) {
+    pa_assert(sa);
+
+    switch (sa->sa_family) {
+        case AF_UNIX:
+            return TRUE;
+
+        case AF_INET:
+            return ((const struct sockaddr_in*) sa)->sin_addr.s_addr == INADDR_LOOPBACK;
+
+        case AF_INET6:
+            return memcmp(&((const struct sockaddr_in6*) sa)->sin6_addr, &in6addr_loopback, sizeof(struct in6_addr)) == 0;
+
+        default:
+            return FALSE;
+    }
+}
+
+pa_bool_t pa_socket_is_local(int fd) {
+
+    union {
+        struct sockaddr sa;
+        struct sockaddr_in in;
+        struct sockaddr_in6 in6;
+#ifdef HAVE_SYS_UN_H
+        struct sockaddr_un un;
+#endif
+    } sa;
+    socklen_t sa_len = sizeof(sa);
+
+    if (getpeername(fd, &sa.sa, &sa_len) < 0)
+        return FALSE;
+
+    return pa_socket_address_is_local(&sa.sa);
+}

Modified: trunk/src/pulsecore/socket-util.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/socket-util.h?rev=2532&root=pulseaudio&r1=2531&r2=2532&view=diff
==============================================================================
--- trunk/src/pulsecore/socket-util.h (original)
+++ trunk/src/pulsecore/socket-util.h Mon Jun 16 20:45:17 2008
@@ -26,6 +26,9 @@
 ***/
 
 #include <sys/types.h>
+#include <sys/socket.h>
+
+#include <pulsecore/macro.h>
 
 void pa_socket_peer_to_string(int fd, char *c, size_t l);
 
@@ -39,4 +42,7 @@
 int pa_unix_socket_is_stale(const char *fn);
 int pa_unix_socket_remove_stale(const char *fn);
 
+pa_bool_t pa_socket_address_is_local(const struct sockaddr *sa);
+pa_bool_t pa_socket_is_local(int fd);
+
 #endif




More information about the pulseaudio-commits mailing list