diff --git a/lib/platform_compat.h b/lib/platform_compat.h index 624fcebd..9d53bcb4 100644 --- a/lib/platform_compat.h +++ b/lib/platform_compat.h @@ -103,6 +103,8 @@ // nanosleep already defined in pthread_time.h on MSYS2 // poll() and pollfd already defined in winsock2.h on MSYS2 + // Explicitly declare poll() to avoid implicit declaration warning + int poll(struct pollfd *fds, unsigned long nfds, int timeout); // sa_family_t might not be defined on some Windows setups #ifndef sa_family_t diff --git a/src/config_parser.c b/src/config_parser.c index 5190f0c3..f04f9902 100644 --- a/src/config_parser.c +++ b/src/config_parser.c @@ -9,9 +9,11 @@ #include #include "../lib/platform_compat.h" #include +#ifndef _WIN32 #include #include #include +#endif #define MAX_LINE_LEN 1024 #define INITIAL_ARRAY_CAPACITY 8 @@ -173,7 +175,13 @@ static int parse_address_and_port(const char *str, struct sockaddr_storage *sock static uint32_t get_netif_index(const char *ifname) { if (!ifname || strlen(ifname) == 0) return 0; +#ifdef _WIN32 + // Windows doesn't have if_nametoindex, return 0 to indicate no specific interface + (void)ifname; + return 0; +#else return if_nametoindex(ifname); +#endif } static struct CFG_CLIENT_LINK* create_client_link(struct CFG_SERVER* local_srv, const char *remote_addr) { diff --git a/src/utun.c b/src/utun.c index 740b53f6..447cb761 100644 --- a/src/utun.c +++ b/src/utun.c @@ -159,6 +159,10 @@ static void remove_pidfile(const char *pidfile) { // Daemonize process static int daemonize(void) { +#ifdef _WIN32 + // Windows doesn't support fork/setsid, just return success + return 0; +#else pid_t pid = fork(); if (pid < 0) { perror("fork"); @@ -196,6 +200,7 @@ static int daemonize(void) { } return 0; +#endif } // Open log file @@ -208,8 +213,12 @@ static FILE* open_logfile(const char *logfile) { return stderr; } - // Set line buffering + // Set line buffering (Windows uses _IOLBF via setvbuf) +#ifdef _WIN32 + setvbuf(fp, NULL, _IOLBF, 0); +#else setlinebuf(fp); +#endif return fp; } @@ -283,7 +292,9 @@ int main(int argc, char *argv[]) { // Setup signal handlers signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); +#ifndef _WIN32 signal(SIGHUP, signal_handler); +#endif // Daemonize if not in foreground if (!args.foreground) {