From: Simon Ruderich Date: Mon, 29 Jul 2013 11:13:33 +0000 (+0200) Subject: Check library functions for success values. X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=19b4321866194060cfc28419d52531a924f1b986;p=tlsproxy%2Ftlsproxy.git Check library functions for success values. --- diff --git a/src/connection.c b/src/connection.c index ed1bc63..b7b9d68 100644 --- a/src/connection.c +++ b/src/connection.c @@ -156,7 +156,7 @@ void handle_connection(int client_socket) { server_socket = connect_to_host(host, port); } - if (server_socket == -1) { + if (server_socket < 0) { LOG(WARNING, "failed to connect to server"); send_forwarding_failure(client_fd_write); goto out; @@ -816,12 +816,12 @@ static int connect_to_host(const char *hostname, const char *port) { server_socket = socket(server->ai_family, server->ai_socktype, server->ai_protocol); - if (server_socket == -1) { + if (server_socket < 0) { LOG_PERROR(DEBUG, "connect_to_host(): socket(), trying next"); continue; } - if (connect(server_socket, server->ai_addr, server->ai_addrlen) != -1) { + if (connect(server_socket, server->ai_addr, server->ai_addrlen) == 0) { break; } LOG_PERROR(DEBUG, "connect_to_host(): connect(), trying next"); diff --git a/src/tlsproxy.c b/src/tlsproxy.c index be1789a..2d2ea1e 100644 --- a/src/tlsproxy.c +++ b/src/tlsproxy.c @@ -153,7 +153,7 @@ int main(int argc, char **argv) { #else server_socket = socket(PF_INET6, SOCK_STREAM, 0); #endif - if (server_socket == -1) { + if (server_socket < 0) { perror("socket()"); return EXIT_FAILURE; } @@ -177,12 +177,12 @@ int main(int argc, char **argv) { server_in.sin6_port = htons((uint16_t)port); /* port to bind to */ #endif if (bind(server_socket, (struct sockaddr *)&server_in, - sizeof(server_in)) == -1) { + sizeof(server_in)) != 0) { perror("bind()"); return EXIT_FAILURE; } /* And accept connections. */ - if (listen(server_socket, 5) == -1) { + if (listen(server_socket, 5) != 0) { perror("listen()"); return EXIT_FAILURE; } @@ -200,7 +200,7 @@ int main(int argc, char **argv) { while (!done) { /* Accept new connection. */ client_socket = accept(server_socket, NULL, NULL); - if (client_socket == -1) { + if (client_socket < 0) { perror("accept()"); break; } diff --git a/tests/client.c b/tests/client.c index 866afd1..2b7fb07 100644 --- a/tests/client.c +++ b/tests/client.c @@ -204,12 +204,12 @@ static int connect_to_host(const char *hostname, const char *port) { server_socket = socket(server->ai_family, server->ai_socktype, server->ai_protocol); - if (server_socket == -1) { + if (server_socket < 0) { perror("connect_to_host(): socket(), trying next"); continue; } - if (connect(server_socket, server->ai_addr, server->ai_addrlen) != -1) { + if (connect(server_socket, server->ai_addr, server->ai_addrlen) == 0) { break; } perror("connect_to_host(): connect(), trying next");