summaryrefslogtreecommitdiff
path: root/sockets.c
diff options
context:
space:
mode:
Diffstat (limited to 'sockets.c')
-rw-r--r--sockets.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/sockets.c b/sockets.c
index 0921e55..0f0eefd 100644
--- a/sockets.c
+++ b/sockets.c
@@ -76,7 +76,7 @@ int createserversocket(char *host, char *port) {
// Create listening socket to listen for bouncer client connections
int createclientsocket(char *listenport) {
- int listener; // listening socket descriptor
+ int listener = -1; // listening socket descriptor
int rv; // return value for getaddrinfo (for error message)
struct addrinfo hints, *ai, *p;
int yes = 1; // for enabling socket options with setsockopt
@@ -119,6 +119,13 @@ int createclientsocket(char *listenport) {
}
}
+ // If both IPv4 and IPv6 failed then give up
+ if (listener < 0) {
+ printf("bouncer-client: failed to create socket, exiting...\n");
+ debugprint(DEBUG_CRIT, "bouncer-client: failed to create socket, exiting...\n");
+ exit(1);
+ }
+
// allow address re-use
setsockopt(listener, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)); // 1 as in non-zero as in enable