diff --git a/library.c b/library.c index af887d8b..440ec9e3 100644 --- a/library.c +++ b/library.c @@ -582,7 +582,7 @@ void openconnect_set_stats_handler(struct openconnect_info *vpninfo, /* Set up a traditional OS-based tunnel device, optionally specified in 'ifname'. */ int openconnect_setup_tun_device(struct openconnect_info *vpninfo, char *vpnc_script, char *ifname) { - int tun_fd; + intptr_t tun_fd; vpninfo->vpnc_script = vpnc_script; vpninfo->ifname = ifname; diff --git a/openconnect-internal.h b/openconnect-internal.h index 6379e001..004cb38b 100644 --- a/openconnect-internal.h +++ b/openconnect-internal.h @@ -455,7 +455,7 @@ int script_config_tun(struct openconnect_info *vpninfo, const char *reason); void os_shutdown_tun(struct openconnect_info *vpninfo); int os_read_tun(struct openconnect_info *vpninfo, struct pkt *pkt, int new_pkt); int os_write_tun(struct openconnect_info *vpninfo, struct pkt *pkt); -int os_setup_tun(struct openconnect_info *vpninfo); +intptr_t os_setup_tun(struct openconnect_info *vpninfo); /* dtls.c */ unsigned char unhex(const char *data); diff --git a/openconnect.h b/openconnect.h index 714269e8..08e54940 100644 --- a/openconnect.h +++ b/openconnect.h @@ -336,9 +336,13 @@ int openconnect_setup_tun_device(struct openconnect_info *vpninfo, char *vpnc_sc /* Pass traffic to a script program (no tun device). */ int openconnect_setup_tun_script(struct openconnect_info *vpninfo, char *tun_script); +#ifdef _WIN32 +/* Caller will provide an overlap-capable handle for the tunnel traffic. */ +int openconnect_setup_tun_fd(struct openconnect_info *vpninfo, intptr_t tun_fd); +#else /* Caller will provide a file descriptor for the tunnel traffic. */ int openconnect_setup_tun_fd(struct openconnect_info *vpninfo, int tun_fd); - +#endif /* Optional call to enable DTLS on the connection. */ int openconnect_setup_dtls(struct openconnect_info *vpninfo, int dtls_attempt_period); diff --git a/tun-win32.c b/tun-win32.c index 1fcf0fcb..d99005bf 100644 --- a/tun-win32.c +++ b/tun-win32.c @@ -192,19 +192,12 @@ static intptr_t open_tun(struct openconnect_info *vpninfo, char *guid, char *nam if (!vpninfo->ifname) vpninfo->ifname = strdup(name); - vpninfo->tun_fh = tun_fh; - vpninfo->tun_rd_overlap.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - monitor_read_fd(vpninfo, tun); - - return 1; + return (intptr_t)tun_fh; } -int os_setup_tun(struct openconnect_info *vpninfo) +intptr_t os_setup_tun(struct openconnect_info *vpninfo) { - if (search_taps(vpninfo, open_tun, 0) != 1) - return -1; - - return 0; + return search_taps(vpninfo, open_tun, 0); } int os_read_tun(struct openconnect_info *vpninfo, struct pkt *pkt, int new_pkt) @@ -277,7 +270,11 @@ void os_shutdown_tun(struct openconnect_info *vpninfo) vpninfo->tun_rd_overlap.hEvent = NULL; } -int openconnect_setup_tun_fd(struct openconnect_info *vpninfo, int tun_fd) +int openconnect_setup_tun_fd(struct openconnect_info *vpninfo, intptr_t tun_fd) { + vpninfo->tun_fh = (HANDLE)tun_fd; + vpninfo->tun_rd_overlap.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + monitor_read_fd(vpninfo, tun); + return 0; } diff --git a/tun.c b/tun.c index 7d676cce..18563490 100644 --- a/tun.c +++ b/tun.c @@ -169,7 +169,7 @@ static int bsd_open_tun(char *tun_name) #define bsd_open_tun(tun_name) open(tun_name, O_RDWR) #endif -int os_setup_tun(struct openconnect_info *vpninfo) +intptr_t os_setup_tun(struct openconnect_info *vpninfo) { int tun_fd = -1; #ifdef IFF_TUN /* Linux */