Commit 83c5b14d authored by David Woodhouse's avatar David Woodhouse

Make openconnect_setup_tun_fd() work on Windows

And use it for openconnect_setup_tun_device() too, like the non-Windows
version does.
Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent d785447b
......@@ -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;
......
......@@ -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);
......
......@@ -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);
......
......@@ -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;
}
......@@ -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 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment