diff options
author | Christian Pointner <equinox@spreadspace.org> | 2011-06-08 23:18:05 +0000 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2011-06-08 23:18:05 +0000 |
commit | d3ac7fce71f7c17ebf1448abbbf6acd1b0cc3adc (patch) | |
tree | efb338b96ff30801f97b019242ff6fe607627d47 /src/streamer.c | |
parent | first working version (diff) |
implemened first version for resolving
Diffstat (limited to 'src/streamer.c')
-rw-r--r-- | src/streamer.c | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/src/streamer.c b/src/streamer.c index 2c108c9..0a068e4 100644 --- a/src/streamer.c +++ b/src/streamer.c @@ -35,6 +35,7 @@ #include <sys/types.h> #include <sys/socket.h> #include <arpa/inet.h> +#include <netdb.h> #include "streamer.h" @@ -67,19 +68,33 @@ static void fdremoved_cb(GstElement* sink, gint fd, gpointer data) int init_server(const char* host, const char* port) { - int server = socket(AF_INET, SOCK_STREAM, 0); - if(server < 0) { - log_printf(ERROR, "streamer: socket() call failed"); + struct addrinfo hints, *res; + res = NULL; + memset (&hints, 0, sizeof (hints)); + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; + hints.ai_family = AF_UNSPEC; + + int errcode = getaddrinfo(host, port, &hints, &res); + if (errcode != 0) { + log_printf(ERROR, "Error resolving address (%s:%s): %s", (host) ? host : "*", (port) ? port : "0", gai_strerror(errcode)); + return -1; + } + if(!res) { + log_printf(ERROR, "getaddrinfo returned no address for %s:%s", (host) ? host : "*", (port) ? port : "0"); return -1; } - - // TODO: resolve host and port struct sockaddr_in local_addr; memset((char *) &local_addr, 0, sizeof(local_addr)); - local_addr.sin_family = AF_INET; - local_addr.sin_port = htons(80); - local_addr.sin_addr.s_addr = htonl(INADDR_ANY); + memcpy(&local_addr, res->ai_addr, res->ai_addrlen); + freeaddrinfo(res); + + int server = socket(AF_INET, SOCK_STREAM, 0); + if(server < 0) { + log_printf(ERROR, "streamer: socket() call failed"); + return -1; + } int on = 1; if (setsockopt(server, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0) { |