diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2013-01-04 10:26:09 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2013-01-04 10:26:09 +0100 |
commit | a650e7a58ae25d32510894f6efbe78ef659db774 (patch) | |
tree | de9c2146c0847048a6e48eda0df222328bbe3923 /debug_syslog.c | |
parent | 10713de6bf9f0c2d9ade248546e63617a9ef9780 (diff) |
Make win32 compatible.
Diffstat (limited to 'debug_syslog.c')
-rw-r--r-- | debug_syslog.c | 34 |
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 |