summaryrefslogtreecommitdiff
path: root/src/tcp.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2010-11-27 03:31:35 +0000
committerChristian Pointner <equinox@spreadspace.org>2010-11-27 03:31:35 +0000
commit4793dc0638330ef5296c126d136489228d9521b0 (patch)
tree25623cd2a2388ec9ad16ac04107f0aaef91daac9 /src/tcp.c
parentadded tcp listener list (diff)
listening on tcp sockets works now
git-svn-id: https://svn.spreadspace.org/tcpproxy/trunk@8 e61f0598-a718-4e21-a8f0-0aadfa62ad6b
Diffstat (limited to 'src/tcp.c')
-rw-r--r--src/tcp.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/tcp.c b/src/tcp.c
index 42db969..0211526 100644
--- a/src/tcp.c
+++ b/src/tcp.c
@@ -29,10 +29,14 @@
#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
#include "datatypes.h"
#include "tcp.h"
+#include "log.h"
char* tcp_endpoint_to_string(tcp_endpoint_t e)
{
@@ -68,3 +72,31 @@ char* tcp_endpoint_to_string(tcp_endpoint_t e)
free(addrstr);
return ret;
}
+
+struct addrinfo* tcp_resolve_endpoint(const char* addr, const char* port, resolv_type_t rt)
+{
+ struct addrinfo hints, *res;
+
+ res = NULL;
+ memset (&hints, 0, sizeof (hints));
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
+
+ switch(rt) {
+ case IPV4_ONLY: hints.ai_family = AF_INET; break;
+ case IPV6_ONLY: hints.ai_family = AF_INET6; break;
+ default: hints.ai_family = AF_UNSPEC; break;
+ }
+
+ int errcode = getaddrinfo(addr, port, &hints, &res);
+ if (errcode != 0) {
+ log_printf(ERROR, "Error resolving local address (%s:%s): %s", (addr) ? addr : "*", port, gai_strerror(errcode));
+ return NULL;
+ }
+ if(!res) {
+ log_printf(ERROR, "getaddrinfo returned no address for %s:%s", addr, port);
+ return NULL;
+ }
+
+ return res;
+}