]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - net.c
net: Always initialize struct sockaddr_storage.
[paraslash.git] / net.c
diff --git a/net.c b/net.c
index 42418e5f20d9e168eb0af5c7da9c2d1ffa1c2127..eaa1cfb81146b3dc4fd7bb11cd41df447dc0e825 100644 (file)
--- a/net.c
+++ b/net.c
@@ -6,11 +6,7 @@
 
 /** \file net.c Networking-related helper functions. */
 
-/*
- * Since glibc 2.8, the _GNU_SOURCE feature test macro must be defined in order
- * to obtain the definition of the ucred structure.
- */
-#define _GNU_SOURCE
+#include "para.h"
 
 #include <netinet/in.h>
 #include <arpa/inet.h>
@@ -32,7 +28,6 @@
 
 #include <regex.h>
 
-#include "para.h"
 #include "error.h"
 #include "net.h"
 #include "string.h"
@@ -180,8 +175,7 @@ char *parse_url(const char *url,
        }
 
        if (*o == ':')
-               if (para_atoi32(++o, port) < 0 ||
-                   *port < 0 || *port > 0xffff)
+               if (para_atoi32(++o, port) < 0 || *port < 0 || *port > 0xffff)
                        goto failed;
        if (host_string_ok(host))
                return host;
@@ -192,6 +186,7 @@ failed:
 
 /**
  * Stringify port number, resolve into service name where defined.
+ *
  * \param port 2-byte port number, in host-byte-order.
  * \param transport Transport protocol name (e.g. "udp", "tcp"), or NULL.
  * \return Pointer to static result buffer.
@@ -381,7 +376,7 @@ int lookup_address(unsigned l4type, bool passive, const char *host,
        struct addrinfo *addr = NULL, hints;
 
        *result = NULL;
-       sprintf(port, "%u", port_number & 0xffff);
+       sprintf(port, "%d", port_number & 0xffff);
        /* Set up address hint structure */
        memset(&hints, 0, sizeof(hints));
        hints.ai_family = AF_UNSPEC;
@@ -608,7 +603,7 @@ static inline int estimated_header_overhead(const int af_type)
  */
 int generic_max_transport_msg_size(int sockfd)
 {
-       struct sockaddr_storage ss;
+       struct sockaddr_storage ss = {0};
        socklen_t sslen = sizeof(ss);
        int af_type = AF_INET;
 
@@ -634,7 +629,7 @@ int generic_max_transport_msg_size(int sockfd)
  */
 char *remote_name(int fd)
 {
-       struct sockaddr_storage ss;
+       struct sockaddr_storage ss = {0};
        const struct sockaddr *sa;
        socklen_t sslen = sizeof(ss);
        char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];