X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Fserver.c;h=9dc0c29b57969c59bfc0a5222f2d33e6dffef3b6;hb=d723b45fc42e04b9179ba29c65efc9484ec2924c;hp=e83a68ab7f0b3bb3b895687647e9681a2c5821cd;hpb=0f8e60fe4f27fd08e021b679079c936076f56799;p=umurmur.git diff --git a/src/server.c b/src/server.c index e83a68a..9dc0c29 100644 --- a/src/server.c +++ b/src/server.c @@ -44,6 +44,7 @@ #include "client.h" #include "conf.h" #include "log.h" +#include "memory.h" #include "timer.h" #include "version.h" #include "util.h" @@ -67,11 +68,11 @@ void checkIPversions() int testsocket = -1; testsocket = socket(PF_INET, SOCK_STREAM, 0); - hasv4 = (errno == EAFNOSUPPORT) ? false : true; + hasv4 = (errno == EAFNOSUPPORT || errno == EPROTONOSUPPORT) ? false : true; if (!(testsocket < 0)) close(testsocket); testsocket = socket(PF_INET6, SOCK_STREAM, 0); - hasv6 = (errno == EAFNOSUPPORT) ? false : true; + hasv6 = (errno == EAFNOSUPPORT || errno == EPROTONOSUPPORT) ? false : true; if (!(testsocket < 0)) close(testsocket); if(!hasv4) @@ -85,7 +86,6 @@ void checkIPversions() Log_info("IPv6 is not supported by this system"); nofServerSocks -= 2; } - if(nofServerSocks == 0) { Log_fatal("Neither IPv4 nor IPv6 are supported by this system"); @@ -95,11 +95,11 @@ void checkIPversions() /* Initialize the address structures for IPv4 and IPv6 */ struct sockaddr_storage** Server_setupAddressesAndPorts() { - struct sockaddr_storage** addresses = calloc(2, sizeof(void*)); + struct sockaddr_storage** addresses = Memory_safeCalloc(2, sizeof(void*)); - struct sockaddr_storage* v4address = calloc(1, sizeof(struct sockaddr_storage)); + struct sockaddr_storage* v4address = Memory_safeCalloc(1, sizeof(struct sockaddr_storage)); v4address->ss_family = AF_INET; - struct sockaddr_storage* v6address = calloc(1, sizeof(struct sockaddr_storage)); + struct sockaddr_storage* v6address = Memory_safeCalloc(1, sizeof(struct sockaddr_storage)); v6address->ss_family = AF_INET6; #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) @@ -209,7 +209,7 @@ void Server_runLoop(struct pollfd* pollfds) void Server_setupTCPSockets(struct sockaddr_storage* addresses[2], struct pollfd* pollfds) { - uint8_t yes = 1; + int yes = 1; int sockets[2]; if (hasv4) { @@ -262,8 +262,7 @@ void Server_setupUDPSockets(struct sockaddr_storage* addresses[2], struct pollfd int val = 0; int sockets[2] = {-1, -1}; - if((udpsocks = calloc(nofServerSocks / 2, sizeof(int))) == NULL) - Log_fatal("Out of memory (%s:%s)", __FILE__, __LINE__); + udpsocks = Memory_safeCalloc(nofServerSocks / 2, sizeof(int)); if (hasv4) { sockets[0] = socket(PF_INET, SOCK_DGRAM, 0); @@ -316,8 +315,7 @@ void Server_run() checkIPversions(); /* max clients + server sokets + client connecting that will be disconnected */ - if ((pollfds = calloc((getIntConf(MAX_CLIENTS) + nofServerSocks + 1) , sizeof(struct pollfd))) == NULL) - Log_fatal("out of memory"); + pollfds = Memory_safeCalloc((getIntConf(MAX_CLIENTS) + nofServerSocks + 1) , sizeof(struct pollfd)); /* Figure out bind address and port */ struct sockaddr_storage** addresses = Server_setupAddressesAndPorts();