Skip to content

Commit

Permalink
Make openconnect_setup_tun_fd() work on Windows
Browse files Browse the repository at this point in the history
And use it for openconnect_setup_tun_device() too, like the non-Windows
version does.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Feb 14, 2014
1 parent d785447 commit 83c5b14
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion library.c
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion openconnect-internal.h
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion openconnect.h
Expand Up @@ -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);

Expand Down
19 changes: 8 additions & 11 deletions tun-win32.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion tun.c
Expand Up @@ -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 */
Expand Down

0 comments on commit 83c5b14

Please sign in to comment.