]> ruderich.org/simon Gitweb - tlsproxy/tlsproxy.git/commitdiff
Check library functions for success values.
authorSimon Ruderich <simon@ruderich.org>
Mon, 29 Jul 2013 11:13:33 +0000 (13:13 +0200)
committerSimon Ruderich <simon@ruderich.org>
Mon, 29 Jul 2013 11:13:33 +0000 (13:13 +0200)
src/connection.c
src/tlsproxy.c
tests/client.c

index ed1bc63c6e030c5349f9d2aa46a179c8d60bf2f9..b7b9d683d6e6840af314dc2d87a4a049f06aa050 100644 (file)
@@ -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");
index be1789a111a8b6356b9200021e211efe443ed7d5..2d2ea1e2cf44f92759a65f58ae33ef0f68e96938 100644 (file)
@@ -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;
         }
index 866afd13dd2a5f43e623019db6c0b5a613890b88..2b7fb07465c41c05bc12992e5a5a751d08cb0949 100644 (file)
@@ -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");