summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 66eb6c7)
raw | patch | inline | side by side (parent: 66eb6c7)
author | octo <octo> | |
Sun, 29 Jan 2006 12:33:00 +0000 (12:33 +0000) | ||
committer | octo <octo> | |
Sun, 29 Jan 2006 12:33:00 +0000 (12:33 +0000) |
Fixed bugs in `network.c'. It compiles now.
src/Makefile.am | patch | blob | history | |
src/network.c | patch | blob | history |
diff --git a/src/Makefile.am b/src/Makefile.am
index a98eab1bce0a90d11f01941bf37919581fe99bbe..2c0e3484570a1c5176c9885e4967ca0c5a921117 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
utils_mount.c utils_mount.h \
common.c common.h \
multicast.c multicast.h \
+ network.c network.h \
plugin.c plugin.h \
configfile.c configfile.h
#collectd_CFLAGS = -DPLUGINDIR='"$(pkglibdir)"'
diff --git a/src/network.c b/src/network.c
index f42693e1c494f90359b1877c4148c8e4a5fef45e..546f5e2d142ad46d03548a5410d5c139ba361018 100644 (file)
--- a/src/network.c
+++ b/src/network.c
#include "network.h"
#include "common.h"
+#include "utils_debug.h"
/*
* From RFC2365:
#define UDP_PORT 25826
/* 1500 - 40 - 8 = Ethernet packet - IPv6 header - UDP header */
-#define BUFF_SIZE 1452
+/* #define BUFF_SIZE 1452 */
#define BUFF_SIZE 4096
static sockent_t *socklist_head = NULL;
-static int network_bind_socket (int fd, const struct addrinfo *ai, const sockent_t *se)
+static int network_bind_socket (const sockent_t *se, const struct addrinfo *ai)
{
int loop = 1;
- if (bind (fd, ai->ai_addr, ai->ai_addrlen) == -1)
+ if (bind (se->fd, ai->ai_addr, ai->ai_addrlen) == -1)
{
syslog (LOG_ERR, "bind: %s", strerror (errno));
return (-1);
@@ -127,7 +128,7 @@ static int network_bind_socket (int fd, const struct addrinfo *ai, const sockent
* single interface; programs running on
* multihomed hosts may need to join the same
* group on more than one interface.*/
- mreq6.ipv6mr_interface = 0;
+ mreq.ipv6mr_interface = 0;
if (setsockopt (se->fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
&loop, sizeof (loop)) == -1)
continue;
}
- assert (sizeof (struct sockaddr_storage) >= ai_ptr->addrlen);
+ assert (sizeof (struct sockaddr_storage) >= ai_ptr->ai_addrlen);
memset (se->addr, '\0', sizeof (struct sockaddr_storage));
- memcpy (se->addr, ai_ptr->ai_addr, ai_ptr->addrlen);
- se->addrlen = ai_ptr->addrlen;
+ memcpy (se->addr, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
+ se->addrlen = ai_ptr->ai_addrlen;
se->fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
se->next = NULL;
}
if (operating_mode == MODE_SERVER)
- if (network_bind_socket (se->fd, ai_ptr, se->addr) != 0)
+ if (network_bind_socket (se, ai_ptr) != 0)
{
free (se->addr);
free (se);
static int network_get_listen_socket (void)
{
- int fd;
- int max_fd;
+ int fd;
+ int max_fd;
+ int status;
fd_set readfds;
sockent_t *se;
char buffer[BUFF_SIZE];
struct sockaddr_storage addr;
+ socklen_t addrlen;
int status;
char *fields[4];
if ((fd = network_get_listen_socket ()) < 0)
return (-1);
- if (recvfrom (fd, buffer, BUFF_SIZE, 0, (struct sockaddr *) &addr, sizeof (addr)) == -1)
+ if (recvfrom (fd, buffer, BUFF_SIZE, 0, (struct sockaddr *) &addr, &addrlen) == -1)
{
syslog (LOG_ERR, "recvfrom: %s", strerror (errno));
return (-1);
return (-1);
}
- status = getnameinfo ((struct sockaddr *) &addr, sizeof (addr),
+ status = getnameinfo ((struct sockaddr *) &addr, addrlen,
*host, BUFF_SIZE, NULL, 0, 0);
if (status != 0)
{
if ((*type = strdup (fields[0])) == NULL)
{
- syslog (LOG_EMERG, "strdup: %s", strerror ());
+ syslog (LOG_EMERG, "strdup: %s", strerror (errno));
free (*host); *host = NULL;
return (-1);
}
if ((*inst = strdup (fields[1])) == NULL)
{
- syslog (LOG_EMERG, "strdup: %s", strerror ());
+ syslog (LOG_EMERG, "strdup: %s", strerror (errno));
free (*host); *host = NULL;
free (*type); *type = NULL;
return (-1);
if ((*value = strdup (fields[2])) == NULL)
{
- syslog (LOG_EMERG, "strdup: %s", strerror ());
+ syslog (LOG_EMERG, "strdup: %s", strerror (errno));
free (*host); *host = NULL;
free (*type); *type = NULL;
free (*inst); *inst = NULL;