Use intptr_t for intermediate cast to gnutls_transport_ptr_t

In Win64, 'long' is still only 32 bits, and isn't enough to avoid the
"cast to pointer from integer of different size" warning. This kind of
braindamage is why intptr_t exists, so use it.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Fix overflow warning in dumb_socketpair() on Win64

The SOCKET type is a pointer, although in practice what's returned really
does look like a file descriptor. It's a low-valued integer such as 0x23
under Wine, 0x54 under Windows 7 in my testing.

The INVALID_SOCKET error return from socket() is defined as (SOCKET)(~0),
or 0xFFFFFFFFFFFFFFFF on Win64. Thus we get errors when assigning it to
an int in the socks[] array. So use -1 here instead.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Fix Windows openconnect_passphrase_from_fsid()

It was leaving the key file open, and using OpenFile() was causing warnings
on Win64 so use CreateFile() instead.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Avoid building against GnuTLS v3.2.0-v3.2.9 on Windows

http://lists.infradead.org/pipermail/openconnect-devel/2014-February/001641.html

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Print a message when ignoring a TAP device due to --interface option

That would have saved me a while....

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Fix error printing when registry open fails

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Print error when no TAP interfaces found

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Move vpnc-script handling after platform detection in configure.ac

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Clean up default vpnc-script handling for Windows

We automatically prepend the current executable's path to the script
name if it's relative, and run it in 'cscript.exe'.

Perhaps it would be nicer if we determined whether the path was relative
or not in autoconf, rather than at runtime.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Update vpnc-script documentation for Windows

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Update build documentation

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Move set_script_env() to script.c

Let's move the environment stuff out of the way so that tun.c can be built
for sane platforms only.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Move script_config_tun() to script.c

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Factor out os_read_tun() from tun_mainloop()

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Factor out os_write_tun() from tun_mainloop()

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Move tun_mainloop() to mainloop.c

It can't live in tun.c because we're about to stop that being built on
Windows.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Split out os_shutdown_tun() for Windows vs. sane platforms

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Move Windows openconnect_setup_tun_fd() to tun-win32.c

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Split out os_setup_tun() for Windows vs. sane platforms

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Move set_tun_mtu() into os_setup_tun()

There's no real reason for this to be in openconnect_setup_tun_device()
after the vpnc-script is run. That's just a historical artifact because
we *used* to attempt to do IP configuration ourselves if there was no
vpnc-script, and we used to do the MTU setup even if there *was*.

In commit ad9c6573c ("Don't attempt to configure Legacy IP address on
tun device.") it was changed to run the script, then set the MTU anyway
just in case the script didn't get it right. But the MTU could actually
have been set much sooner.

In fact it probably doesn't need to be done at all these days, since
nobody should still be using a vpnc-script that old. But it doesn't hurt.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>