summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debug_syslog.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/debug_syslog.c b/debug_syslog.c
index 9a2afbd..2a8abb3 100644
--- a/debug_syslog.c
+++ b/debug_syslog.c
@@ -31,11 +31,19 @@
#include <string.h>
#include <time.h>
+#ifdef WIN32
+#include <ws2tcpip.h>
+#include <WinSock2.h>
+typedef SOCKET socket_t;
+#else
+typedef int socket_t;
#include <sys/socket.h>
+#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
+#endif
+
#include <unistd.h>
-#include <netinet/in.h>
#include <errno.h>
#include "debug_util.h"
@@ -58,8 +66,26 @@ static struct sockaddr_in dbg_syslog_sockaddr;
static pid_t pid;
static char execname[SYSLOG_LENOFEXECNAME];
+#ifdef WIN32
+static void wsastartup()
+{
+ WORD wVersionRequested = MAKEWORD(2, 0);
+ WSADATA wsaData;
+
+ int ret = WSAStartup(wVersionRequested, &wsaData);
+ if(ret != 0) {
+ fprintf(stderr, "WSAStartup failed.\n");
+ }
+}
+#endif
+
void dbg_syslog_init(const char* host, int port)
{
+
+#ifdef WIN32
+ wsastartup();
+#endif
+
printf("Initializing syslog module remote %s:%d\n", host, port);
if ( (dbg_syslog_sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
fprintf(stderr, "Failed to create socket\n");
@@ -220,7 +246,13 @@ void dbg_syslog_output(char* msg)
void dbg_syslog_close() {
printf("Closing syslog module\n");
if(dbg_syslog_sock < 0) return;
+
+#ifdef WIN32
+ closesocket(dbg_syslog_sock);
+ WSACleanup();
+#else
close(dbg_syslog_sock);
+#endif
}
#ifdef TEST_DEBUG_SYSLOG