diff options
author | sr | 2013-01-15 17:57:27 +0100 |
---|---|---|
committer | sr | 2013-01-15 17:57:27 +0100 |
commit | 2d9e630a430e079ec30f674de1abbd7f4a186657 (patch) | |
tree | efb3f67a04a7dcc1f6889398a78059e31227c50b /src/server/net.c | |
parent | [SERVER] Add socket helper module to simplify connection setup (diff) | |
download | dnbd3-2d9e630a430e079ec30f674de1abbd7f4a186657.tar.gz dnbd3-2d9e630a430e079ec30f674de1abbd7f4a186657.tar.xz dnbd3-2d9e630a430e079ec30f674de1abbd7f4a186657.zip |
[SERVER] Add IPv6 support (clients and RPC connections)
Diffstat (limited to 'src/server/net.c')
-rw-r--r-- | src/server/net.c | 42 |
1 files changed, 1 insertions, 41 deletions
diff --git a/src/server/net.c b/src/server/net.c index bb395fb..f28fc25 100644 --- a/src/server/net.c +++ b/src/server/net.c @@ -25,13 +25,10 @@ #include <unistd.h> #include <pthread.h> #include <fcntl.h> -#include <sys/socket.h> #include <sys/sendfile.h> #include <sys/types.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netinet/tcp.h> +#include "sockhelper.h" #include "helper.h" #include "server.h" #include "saveload.h" @@ -435,40 +432,3 @@ void *dnbd3_handle_query(void *dnbd3_client) dnbd3_free_client(client); pthread_exit((void *) 0); } - -int dnbd3_setup_socket() -{ - int sock; - struct sockaddr_in server; - - // Create socket - sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); - if (sock < 0) - { - memlogf("ERROR: Socket setup failure\n"); - return -1; - } - const int opt = 1; - setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); - - memset(&server, 0, sizeof(server)); - server.sin_family = AF_INET; // IPv4 - server.sin_addr.s_addr = htonl(INADDR_ANY); // Take all IPs - server.sin_port = htons(PORT); // set port number - - // Bind to socket - if (bind(sock, (struct sockaddr *) &server, sizeof(server)) < 0) - { - memlogf("ERROR: Bind failure\n"); - return -1; - } - - // Listen on socket - if (listen(sock, 100) == -1) - { - memlogf("ERROR: Listen failure\n"); - return -1; - } - - return sock; -} |