lib/tsocket: add tsocket_address_is_unix() function
authorStefan Metzmacher <metze@samba.org>
Tue, 27 Apr 2010 08:41:46 +0000 (10:41 +0200)
committerStefan Metzmacher <metze@samba.org>
Tue, 27 Apr 2010 11:00:24 +0000 (13:00 +0200)
metze

lib/tsocket/tsocket.h
lib/tsocket/tsocket_bsd.c

index a008fd8232f1d6779d1a472fe0fb421fd9ac0dab..d4f9e872d3fed5988e00113803be24a0d4b9d624 100644 (file)
@@ -575,6 +575,16 @@ uint16_t tsocket_address_inet_port(const struct tsocket_address *addr);
 int tsocket_address_inet_set_port(struct tsocket_address *addr,
                                  uint16_t port);
 
+/**
+ * @brief Find out if the tsocket_address represents an unix domain endpoint.
+ *
+ * @param[in]  addr     The tsocket_address pointer
+ *
+ * @return              true if addr represents an unix domain endpoint,
+ *                      otherwise false.
+ */
+bool tsocket_address_is_unix(const struct tsocket_address *addr);
+
 #ifdef DOXYGEN
 /**
  * @brief Create a tsocket_address for a unix domain endpoint addresses.
@@ -586,6 +596,8 @@ int tsocket_address_inet_set_port(struct tsocket_address *addr,
  * @param[in]  _addr    The tsocket_address pointer to store the information.
  *
  * @return              0 on success, -1 on error with errno set.
+ *
+ * @see tsocket_address_is_unix()
  */
 int tsocket_address_unix_from_path(TALLOC_CTX *mem_ctx,
                                   const char *path,
index 5adf9214c8ee9d80a90ce72c4aed92b17c0057ae..4a8a63e20bf4b110f6bb477f0177b0d3039a4505 100644 (file)
@@ -503,6 +503,23 @@ int tsocket_address_inet_set_port(struct tsocket_address *addr,
        return 0;
 }
 
+bool tsocket_address_is_unix(const struct tsocket_address *addr)
+{
+       struct tsocket_address_bsd *bsda = talloc_get_type(addr->private_data,
+                                          struct tsocket_address_bsd);
+
+       if (!bsda) {
+               return false;
+       }
+
+       switch (bsda->u.sa.sa_family) {
+       case AF_UNIX:
+               return true;
+       }
+
+       return false;
+}
+
 int _tsocket_address_unix_from_path(TALLOC_CTX *mem_ctx,
                                    const char *path,
                                    struct tsocket_address **_addr,