Code

Initialize `addrlen' before using. This might be the reason for `getnameinfo' failing..
[collectd.git] / src / network.c
index ddc36e772176aa57715471ff652ebb7c5229d82a..3fe25fd46274c5d508a4e38b7877dca7640f1a8a 100644 (file)
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include <netdb.h>
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <netdb.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <syslog.h>
 #include <errno.h>
-#include <assert.h>
 
 #include "network.h"
 #include "common.h"
@@ -164,7 +163,7 @@ int network_create_socket (const char *node, const char *service)
        ai_hints.ai_flags    = AI_PASSIVE | AI_ADDRCONFIG;
        ai_hints.ai_family   = PF_UNSPEC;
        ai_hints.ai_socktype = SOCK_DGRAM;
-       ai_hints.ai_protocol = IPPROTO_UDP; /* XXX is this right here?!? */
+       ai_hints.ai_protocol = IPPROTO_UDP;
 
        if ((ai_return = getaddrinfo (node, service, &ai_hints, &ai_list)) != 0)
        {
@@ -347,6 +346,7 @@ int network_receive (char **host, char **type, char **inst, char **value)
        if ((fd = network_get_listen_socket ()) < 0)
                return (-1);
 
+       addrlen = sizeof (addr);
        if (recvfrom (fd, buffer, BUFF_SIZE, 0, (struct sockaddr *) &addr, &addrlen) == -1)
        {
                syslog (LOG_ERR, "recvfrom: %s", strerror (errno));