From: Florian Forster Date: Tue, 28 Jan 2014 10:38:37 +0000 (+0100) Subject: libcollectdclient: Add defines for Windows compatibility. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=4a55c973d5716d61b9abfcbf14f0d6dccc4c5dbe;p=collectd.git libcollectdclient: Add defines for Windows compatibility. --- diff --git a/src/libcollectdclient/client.c b/src/libcollectdclient/client.c index 726f25d4..c7251822 100644 --- a/src/libcollectdclient/client.c +++ b/src/libcollectdclient/client.c @@ -1,6 +1,6 @@ /** * libcollectdclient - src/libcollectdclient/client.c - * Copyright (C) 2008-2012 Florian octo Forster + * Copyright (C) 2008-2014 Florian octo Forster * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -34,6 +34,18 @@ #include "collectd/lcc_features.h" +#if WIN32 + +#include +#include +#include +#include +#include +#include +#include + +#else + #include #include #include @@ -46,6 +58,8 @@ #include #include +#endif + #include "collectd/client.h" /* NI_MAXHOST has been obsoleted by RFC 3493 which is a reason for SunOS 5.11 @@ -378,6 +392,7 @@ static int lcc_sendreceive (lcc_connection_t *c, /* {{{ */ return (status); } /* }}} int lcc_sendreceive */ +#if !WIN32 static int lcc_open_unixsocket (lcc_connection_t *c, const char *path) /* {{{ */ { struct sockaddr_un sa; @@ -419,6 +434,7 @@ static int lcc_open_unixsocket (lcc_connection_t *c, const char *path) /* {{{ */ return (0); } /* }}} int lcc_open_unixsocket */ +#endif /* !WIN32 */ static int lcc_open_netsocket (lcc_connection_t *c, /* {{{ */ const char *addr_orig) @@ -545,11 +561,13 @@ static int lcc_open_socket (lcc_connection_t *c, const char *addr) /* {{{ */ assert (c->fh == NULL); assert (addr != NULL); +#if !WIN32 if (strncmp ("unix:", addr, strlen ("unix:")) == 0) status = lcc_open_unixsocket (c, addr + strlen ("unix:")); else if (addr[0] == '/') status = lcc_open_unixsocket (c, addr); else +#endif status = lcc_open_netsocket (c, addr); return (status); diff --git a/src/libcollectdclient/collectd/network.h b/src/libcollectdclient/collectd/network.h index 049f7f02..d6c4678f 100644 --- a/src/libcollectdclient/collectd/network.h +++ b/src/libcollectdclient/collectd/network.h @@ -65,7 +65,7 @@ int lcc_server_destroy (lcc_network_t *net, lcc_server_t *srv); /* Configure servers */ int lcc_server_set_ttl (lcc_server_t *srv, uint8_t ttl); -int lcc_server_set_interface (lcc_server_t *srv, char const *interface); +int lcc_server_set_interface (lcc_server_t *srv, char const *ifname); int lcc_server_set_security_level (lcc_server_t *srv, lcc_security_level_t level, const char *username, const char *password); diff --git a/src/libcollectdclient/network.c b/src/libcollectdclient/network.c index ddb3b5b9..aa599384 100644 --- a/src/libcollectdclient/network.c +++ b/src/libcollectdclient/network.c @@ -1,6 +1,6 @@ /** * collectd - src/libcollectdclient/network.c - * Copyright (C) 2005-2013 Florian Forster + * Copyright (C) 2005-2014 Florian Forster * Copyright (C) 2010 Max Henkel * * Permission is hereby granted, free of charge, to any person obtaining a @@ -26,6 +26,16 @@ * Max Henkel **/ +#if WIN32 + +#include +#include +#include +#include +#include + +#else + #include "collectd.h" #include @@ -47,6 +57,8 @@ # include #endif +#endif /* !WIN32 */ + #include "collectd/network.h" #include "collectd/network_buffer.h" @@ -164,7 +176,7 @@ static int server_open_socket (lcc_server_t *srv) /* {{{ */ optname = IP_TTL; setsockopt (srv->fd, IPPROTO_IP, optname, - &srv->ttl, + (void *) &srv->ttl, sizeof (srv->ttl)); } else if (ai_ptr->ai_family == AF_INET6) @@ -179,7 +191,7 @@ static int server_open_socket (lcc_server_t *srv) /* {{{ */ optname = IPV6_UNICAST_HOPS; setsockopt (srv->fd, IPPROTO_IPV6, optname, - &srv->ttl, + (void *) &srv->ttl, sizeof (srv->ttl)); } @@ -385,15 +397,21 @@ int lcc_server_set_ttl (lcc_server_t *srv, uint8_t ttl) /* {{{ */ return (0); } /* }}} int lcc_server_set_ttl */ -int lcc_server_set_interface (lcc_server_t *srv, char const *interface) /* {{{ */ +#if WIN32 +int lcc_server_set_interface (lcc_server_t *srv, char const *ifname) /* {{{ */ +{ + return (-1); +} /* }}} int lcc_server_set_interface */ +#else +int lcc_server_set_interface (lcc_server_t *srv, char const *ifname) /* {{{ */ { int if_index; int status; - if ((srv == NULL) || (interface == NULL)) + if ((srv == NULL) || (ifname == NULL)) return (EINVAL); - if_index = if_nametoindex (interface); + if_index = if_nametoindex (ifname); if (if_index == 0) return (ENOENT); @@ -425,7 +443,7 @@ int lcc_server_set_interface (lcc_server_t *srv, char const *interface) /* {{{ * #endif status = setsockopt (srv->fd, IPPROTO_IP, IP_MULTICAST_IF, - &mreq, sizeof (mreq)); + (void *) &mreq, sizeof (mreq)); if (status != 0) return (status); @@ -441,7 +459,7 @@ int lcc_server_set_interface (lcc_server_t *srv, char const *interface) /* {{{ * if (IN6_IS_ADDR_MULTICAST (&addr->sin6_addr)) { status = setsockopt (srv->fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, - &if_index, sizeof (if_index)); + (void *) &if_index, sizeof (if_index)); if (status != 0) return (status); @@ -452,13 +470,14 @@ int lcc_server_set_interface (lcc_server_t *srv, char const *interface) /* {{{ * /* else: Not a multicast interface. */ #if defined(SO_BINDTODEVICE) status = setsockopt (srv->fd, SOL_SOCKET, SO_BINDTODEVICE, - interface, strlen (interface) + 1); + ifname, strlen (ifname) + 1); if (status != 0) return (-1); #endif return (0); } /* }}} int lcc_server_set_interface */ +#endif /* !WIN32 */ int lcc_server_set_security_level (lcc_server_t *srv, /* {{{ */ lcc_security_level_t level, diff --git a/src/libcollectdclient/network_buffer.c b/src/libcollectdclient/network_buffer.c index 7b066204..b4767942 100644 --- a/src/libcollectdclient/network_buffer.c +++ b/src/libcollectdclient/network_buffer.c @@ -1,6 +1,6 @@ /** * collectd - src/libcollectdclient/network_buffer.c - * Copyright (C) 2010-2012 Florian octo Forster + * Copyright (C) 2010-2014 Florian octo Forster * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -24,7 +24,17 @@ * Florian octo Forster **/ -#include "config.h" +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#if WIN32 + +#include +#include +#include + +#else #include #include @@ -57,6 +67,8 @@ GCRY_THREAD_OPTION_PTHREAD_IMPL; #endif +#endif /* !WIN32 */ + #include "collectd/network_buffer.h" #define TYPE_HOST 0x0000 @@ -80,6 +92,10 @@ GCRY_THREAD_OPTION_PTHREAD_IMPL; #define PART_SIGNATURE_SHA256_SIZE 36 #define PART_ENCRYPTION_AES256_SIZE 42 +#ifndef ENOTSUP +# define ENOTSUP -1 +#endif + #define ADD_GENERIC(nb,srcptr,size) do { \ assert ((size) <= (nb)->free); \ memcpy ((nb)->ptr, (srcptr), (size)); \ @@ -502,6 +518,7 @@ static int nb_add_value_list (lcc_network_buffer_t *nb, /* {{{ */ return (0); } /* }}} int nb_add_value_list */ +/* TODO: Add encryption for Windows */ #if HAVE_LIBGCRYPT static int nb_add_signature (lcc_network_buffer_t *nb) /* {{{ */ {