From 63c60b1379bc038a8914ea89e64c3e129d20108f Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Thu, 21 Aug 2014 16:38:33 +0200 Subject: [PATCH 1/6] use windows types and return codes for socket errors That is, use SOCKET instead of int for cmd_pipe, and return INVALID socket for cmd_pipe. Signed-off-by: Nikos Mavrogiannopoulos --- compat.c | 2 +- library.c | 17 ++++++++++++----- openconnect-internal.h | 2 +- openconnect.h | 11 ++++++----- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/compat.c b/compat.c index 1dfed88..b1d4995 100644 --- a/compat.c +++ b/compat.c @@ -338,7 +338,7 @@ WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * sockets must be closed with closesocket() regardless. */ -int dumb_socketpair(int socks[2], int make_overlapped) +SOCKET dumb_socketpair(SOCKET socks[2], int make_overlapped) { union { struct sockaddr_in inaddr; diff --git a/library.c b/library.c index 0e77c3b..8edf4c2 100644 --- a/library.c +++ b/library.c @@ -432,21 +432,28 @@ void openconnect_set_cancel_fd(struct openconnect_info *vpninfo, int fd) vpninfo->cmd_fd = fd; } -int openconnect_setup_cmd_pipe(struct openconnect_info *vpninfo) +#ifdef _WIN32 +# define CMD_PIPE_ERR INVALID_SOCKET +#else +# define CMD_PIPE_ERR -EIO +#endif + +SOCKET openconnect_setup_cmd_pipe(struct openconnect_info *vpninfo) { - int pipefd[2]; + SOCKET pipefd[2]; #ifdef _WIN32 if (dumb_socketpair(pipefd, 0)) - return -EIO; + return CMD_PIPE_ERR; #else if (pipe(pipefd) < 0) - return -EIO; + return CMD_PIPE_ERR; #endif + if (set_sock_nonblock(pipefd[0]) || set_sock_nonblock(pipefd[1])) { close(pipefd[0]); close(pipefd[1]); - return -EIO; + return CMD_PIPE_ERR; } vpninfo->cmd_fd = pipefd[0]; vpninfo->cmd_fd_write = pipefd[1]; diff --git a/openconnect-internal.h b/openconnect-internal.h index bf25338..089dafc 100644 --- a/openconnect-internal.h +++ b/openconnect-internal.h @@ -527,7 +527,7 @@ void openconnect__win32_sock_init(); #undef inet_pton #define inet_pton openconnect__win32_inet_pton int openconnect__win32_inet_pton(int af, const char *src, void *dst); -int dumb_socketpair(int socks[2], int make_overlapped); +SOCKET dumb_socketpair(SOCKET socks[2], int make_overlapped); #else #define closesocket close #ifndef O_BINARY diff --git a/openconnect.h b/openconnect.h index ea0e009..c15d6a9 100644 --- a/openconnect.h +++ b/openconnect.h @@ -24,10 +24,6 @@ #include #include -#ifdef _WIN32 -#define uid_t unsigned -#endif - #define OPENCONNECT_API_VERSION_MAJOR 3 #define OPENCONNECT_API_VERSION_MINOR 4 @@ -390,7 +386,12 @@ void openconnect_set_cancel_fd(struct openconnect_info *vpninfo, int fd); to the library. This returns a file descriptor to the write side of the pipe. Both sides will be closed by openconnect_vpninfo_free(). This replaces openconnect_set_cancel_fd(). */ -int openconnect_setup_cmd_pipe(struct openconnect_info *vpninfo); +#ifdef _WIN32 +SOCKET +#else +int +#endif +openconnect_setup_cmd_pipe(struct openconnect_info *vpninfo); const char *openconnect_get_version(void); -- 1.9.3