Merge branch 'collectd-5.8'
[collectd.git] / src / libcollectdclient / client.c
index c3cd414..df6fd96 100644 (file)
  *   Florian octo Forster <octo at collectd.org>
  **/
 
-#if HAVE_CONFIG_H
-#include "config.h"
+#ifdef WIN32
+#include "gnulib_config.h"
+#include <winsock2.h>
 #endif
 
+#include "config.h"
+
 #if !defined(__GNUC__) || !__GNUC__
 #define __attribute__(x) /**/
 #endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/socket.h>
 #include <sys/types.h>
-#include <sys/un.h>
 #include <unistd.h>
 
+#ifndef WIN32
+#include <sys/socket.h>
+#include <sys/un.h>
+#endif
+
 #include "collectd/client.h"
 
 /* NI_MAXHOST has been obsoleted by RFC 3493 which is a reason for SunOS 5.11
 #endif
 #endif
 
+#ifdef WIN32
+#define AI_ADDRCONFIG 0
+#endif
+
 /* Secure/static macros. They work like `strcpy' and `strcat', but assure null
  * termination. They work for static buffers only, because they use `sizeof'.
  * The `SSTRCATF' combines the functionality of `snprintf' and `strcat' which
 #define LCC_SET_ERRSTR(c, ...)                                                 \
   do {                                                                         \
     snprintf((c)->errbuf, sizeof((c)->errbuf), __VA_ARGS__);                   \
-    (c)->errbuf[sizeof((c)->errbuf) - 1] = 0;                                  \
   } while (0)
 
 /*
  */
 struct lcc_connection_s {
   FILE *fh;
-  char errbuf[1024];
+  char errbuf[2048];
 };
 
 struct lcc_response_s {
@@ -370,6 +379,10 @@ static int lcc_sendreceive(lcc_connection_t *c, /* {{{ */
 
 static int lcc_open_unixsocket(lcc_connection_t *c, const char *path) /* {{{ */
 {
+#ifdef WIN32
+  lcc_set_errno(c, ENOTSUP);
+  return -1;
+#else
   struct sockaddr_un sa = {0};
   int fd;
   int status;
@@ -404,6 +417,7 @@ static int lcc_open_unixsocket(lcc_connection_t *c, const char *path) /* {{{ */
   }
 
   return 0;
+#endif /* WIN32 */
 } /* }}} int lcc_open_unixsocket */
 
 static int lcc_open_netsocket(lcc_connection_t *c, /* {{{ */