chiark / gitweb /
lib/client.[ch]: Add functions for reading the connection endpoint addresses.
[disorder] / lib / client.c
index 1967e0eea90a813225fd8570611c6088f242f771..fdf0abe1e22e55a63b0bd8b97ccefa00091f217d 100644 (file)
@@ -41,9 +41,6 @@
 #if HAVE_NETDB_H
 # include <netdb.h>
 #endif
-#if HAVE_PCRE_H
-# include <pcre.h>
-#endif
 
 #include "log.h"
 #include "mem.h"
@@ -122,6 +119,24 @@ int disorder_client_af(disorder_client *c) {
   return c->family;
 }
 
+/** @brief Determine the local socket address of this client */
+int disorder_client_sockname(disorder_client *c,
+                            struct sockaddr *sa, socklen_t *len_inout) {
+  int rc;
+  if((rc = getsockname(c->sio.sd, sa, len_inout)))
+    disorder_error(errno, "failed to read client socket name");
+  return rc;
+}
+
+/** @brief Determine the remote peer address for this client */
+int disorder_client_peername(disorder_client *c,
+                            struct sockaddr *sa, socklen_t *len_inout) {
+  int rc;
+  if((rc = getpeername(c->sio.sd, sa, len_inout)))
+    disorder_error(errno, "failed to read client socket name");
+  return rc;
+}
+
 /** @brief Read a response line
  * @param c Client
  * @param rp Where to store response, or NULL (UTF-8)