diff --git a/configure.in b/configure.in index 67da33d..9c5d448 100644 --- a/configure.in +++ b/configure.in @@ -1,7 +1,7 @@ # AC_PREREQ(2.57) AC_INIT(libssh2, [-], libssh2-devel@lists.sourceforge.net) AC_CONFIG_SRCDIR([src]) -AC_CONFIG_HEADER([src/libssh2_config.h example/simple/config.h]) +AC_CONFIG_HEADER([src/libssh2_config.h]) AM_MAINTAINER_MODE dnl SED is needed by some of the tools @@ -61,6 +61,7 @@ AC_PROG_CC AC_PROG_INSTALL AC_PROG_LN_S AC_PROG_MAKE_SET +AC_LIBTOOL_WIN32_DLL AC_PROG_LIBTOOL AC_C_BIGENDIAN if test -z "$PKG_CONFIG"; then @@ -258,6 +259,7 @@ AC_HELP_STRING([--disable-debug],[Disable debug options]), AC_CHECK_HEADERS([errno.h fcntl.h stdio.h stdlib.h unistd.h sys/uio.h]) AC_CHECK_HEADERS([sys/select.h sys/socket.h sys/ioctl.h sys/time.h]) AC_CHECK_HEADERS([arpa/inet.h netinet/in.h]) +AC_CHECK_HEADERS([windows.h ws2tcpip.h winsock2.h]) AC_CHECK_FUNCS(poll gettimeofday select strtoll) case $host in diff --git a/example/simple/Makefile.am b/example/simple/Makefile.am index 30d465d..3b56d13 100644 --- a/example/simple/Makefile.am +++ b/example/simple/Makefile.am @@ -10,6 +10,6 @@ noinst_PROGRAMS = ssh2 \ sftp_RW_nonblock \ sftpdir sftpdir_nonblock -INCLUDES = -I. -I$(top_srcdir)/include +INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/include LDADD = $(top_builddir)/src/libssh2.la diff --git a/example/simple/scp.c b/example/simple/scp.c index 07a781d..745faae 100644 --- a/example/simple/scp.c +++ b/example/simple/scp.c @@ -1,10 +1,10 @@ /* - * $Id: scp.c,v 1.10 2007/08/09 01:10:11 dfandrich Exp $ + * $Id: scp.c,v 1.11 2008/11/10 16:48:41 bagder Exp $ * * Sample showing how to do a simple SCP transfer. */ -#include "config.h" +#include "libssh2_config.h" #include #ifdef HAVE_WINSOCK2_H @@ -50,7 +50,7 @@ int main(int argc, char *argv[]) #ifdef WIN32 WSADATA wsadata; - WSAStartup(WINSOCK_VERSION, &wsadata); + WSAStartup(MAKEWORD(2,0), &wsadata); #endif if (argc > 1) { diff --git a/example/simple/scp_nonblock.c b/example/simple/scp_nonblock.c index 58d1386..432e150 100644 --- a/example/simple/scp_nonblock.c +++ b/example/simple/scp_nonblock.c @@ -1,10 +1,10 @@ /* - * $Id: scp_nonblock.c,v 1.12 2008/09/30 08:55:35 bagder Exp $ + * $Id: scp_nonblock.c,v 1.13 2008/11/10 16:48:41 bagder Exp $ * * Sample showing how to do SCP transfers in a non-blocking manner. */ -#include "config.h" +#include "libssh2_config.h" #include #ifdef HAVE_WINSOCK2_H @@ -53,7 +53,7 @@ int main(int argc, char *argv[]) #ifdef WIN32 WSADATA wsadata; - WSAStartup(WINSOCK_VERSION, &wsadata); + WSAStartup(MAKEWORD(2,0), &wsadata); #endif if (argc > 1) { @@ -94,7 +94,12 @@ int main(int argc, char *argv[]) #elif defined(HAVE_IOCTLSOCKET) ioctlsocket(sock, FIONBIO, &flag); #else +#ifdef WIN32 + u_long mode = 1; + ioctlsocket (sock, FIONBIO, &mode); +#else #error "add support for setting the socket non-blocking here" +#endif #endif /* Create a session instance */ diff --git a/example/simple/scp_write.c b/example/simple/scp_write.c index c751b6c..8c5a8ad 100644 --- a/example/simple/scp_write.c +++ b/example/simple/scp_write.c @@ -1,10 +1,10 @@ /* - * $Id: scp_write.c,v 1.5 2007/08/09 01:10:11 dfandrich Exp $ + * $Id: scp_write.c,v 1.6 2008/11/10 16:48:41 bagder Exp $ * * Sample showing how to do a simple SCP transfer. */ -#include "config.h" +#include "libssh2_config.h" #include #ifdef HAVE_WINSOCK2_H @@ -54,7 +54,7 @@ int main(int argc, char *argv[]) #ifdef WIN32 WSADATA wsadata; - WSAStartup(WINSOCK_VERSION, &wsadata); + WSAStartup(MAKEWORD(2,0), &wsadata); #endif if (argc > 1) { diff --git a/example/simple/scp_write_nonblock.c b/example/simple/scp_write_nonblock.c index 98fbbaf..d57a8b1 100644 --- a/example/simple/scp_write_nonblock.c +++ b/example/simple/scp_write_nonblock.c @@ -1,10 +1,10 @@ /* - * $Id: scp_write_nonblock.c,v 1.8 2008/09/30 08:55:35 bagder Exp $ + * $Id: scp_write_nonblock.c,v 1.9 2008/11/10 16:48:41 bagder Exp $ * * Sample showing how to do a simple SCP transfer. */ -#include "config.h" +#include "libssh2_config.h" #include @@ -58,7 +58,7 @@ int main(int argc, char *argv[]) #ifdef WIN32 WSADATA wsadata; - WSAStartup(WINSOCK_VERSION, &wsadata); + WSAStartup(MAKEWORD(2,0), &wsadata); #endif if (argc > 1) { @@ -111,7 +111,12 @@ int main(int argc, char *argv[]) #elif defined(HAVE_IOCTLSOCKET) ioctlsocket(sock, FIONBIO, &flag); #else +#ifdef WIN32 + u_long mode = 1; + ioctlsocket (sock, FIONBIO, &mode); +#else #error "add support for setting the socket non-blocking here" +#endif #endif /* Create a session instance diff --git a/example/simple/sftp.c b/example/simple/sftp.c index 4d65d24..156ad3a 100644 --- a/example/simple/sftp.c +++ b/example/simple/sftp.c @@ -1,5 +1,5 @@ /* - * $Id: sftp.c,v 1.14 2007/09/24 12:14:18 bagder Exp $ + * $Id: sftp.c,v 1.15 2008/11/10 16:48:41 bagder Exp $ * * Sample showing how to do SFTP transfers. * @@ -9,7 +9,7 @@ * "sftp 192.168.0.1 user password /tmp/secrets -p|-i|-k" */ -#include "config.h" +#include "libssh2_config.h" #include #include @@ -80,7 +80,7 @@ int main(int argc, char *argv[]) #ifdef WIN32 WSADATA wsadata; - WSAStartup(WINSOCK_VERSION, &wsadata); + WSAStartup(MAKEWORD(2,0), &wsadata); #endif if (argc > 1) { diff --git a/example/simple/sftp_RW_nonblock.c b/example/simple/sftp_RW_nonblock.c index 1de11af..d800387 100644 --- a/example/simple/sftp_RW_nonblock.c +++ b/example/simple/sftp_RW_nonblock.c @@ -1,5 +1,5 @@ /* - * $Id: sftp_RW_nonblock.c,v 1.11 2008/09/30 08:55:35 bagder Exp $ + * $Id: sftp_RW_nonblock.c,v 1.12 2008/11/10 16:48:41 bagder Exp $ * * Sample showing how to do SFTP transfers in a non-blocking manner. * @@ -9,7 +9,7 @@ * Using the SFTP server running on 127.0.0.1 */ -#include "config.h" +#include "libssh2_config.h" #include #include @@ -66,7 +66,7 @@ int main(int argc, char *argv[]) #ifdef WIN32 WSADATA wsadata; - WSAStartup(WINSOCK_VERSION, &wsadata); + WSAStartup(MAKEWORD(2,0), &wsadata); #endif /* Ultra basic "connect to port 22 on localhost" @@ -93,7 +93,12 @@ int main(int argc, char *argv[]) #elif defined(HAVE_IOCTLSOCKET) ioctlsocket(sock, FIONBIO, &flag); #else +#ifdef WIN32 + u_long mode = 1; + ioctlsocket (sock, FIONBIO, &mode); +#else #error "add support for setting the socket non-blocking here" +#endif #endif /* Create a session instance diff --git a/example/simple/sftp_mkdir.c b/example/simple/sftp_mkdir.c index e5550ba..20deef7 100644 --- a/example/simple/sftp_mkdir.c +++ b/example/simple/sftp_mkdir.c @@ -1,5 +1,5 @@ /* - * $Id: sftp_mkdir.c,v 1.7 2007/08/09 01:10:11 dfandrich Exp $ + * $Id: sftp_mkdir.c,v 1.8 2008/11/10 16:48:41 bagder Exp $ * * Sample showing how to do SFTP mkdir * @@ -9,7 +9,7 @@ * "sftp 192.168.0.1 user password /tmp/sftp_mkdir" */ -#include "config.h" +#include "libssh2_config.h" #include #include @@ -51,7 +51,7 @@ int main(int argc, char *argv[]) #ifdef WIN32 WSADATA wsadata; - WSAStartup(WINSOCK_VERSION, &wsadata); + WSAStartup(MAKEWORD(2,0), &wsadata); #endif if (argc > 1) { diff --git a/example/simple/sftp_mkdir_nonblock.c b/example/simple/sftp_mkdir_nonblock.c index 93466c4..58bdc91 100644 --- a/example/simple/sftp_mkdir_nonblock.c +++ b/example/simple/sftp_mkdir_nonblock.c @@ -1,5 +1,5 @@ /* - * $Id: sftp_mkdir_nonblock.c,v 1.10 2008/09/30 08:55:35 bagder Exp $ + * $Id: sftp_mkdir_nonblock.c,v 1.11 2008/11/10 16:48:41 bagder Exp $ * * Sample showing how to do SFTP non-blocking mkdir. * @@ -9,7 +9,7 @@ * "sftp 192.168.0.1 user password /tmp/sftp_write_nonblock.c" */ -#include "config.h" +#include "libssh2_config.h" #include #include @@ -54,7 +54,7 @@ int main(int argc, char *argv[]) #ifdef WIN32 WSADATA wsadata; - WSAStartup(WINSOCK_VERSION, &wsadata); + WSAStartup(MAKEWORD(2,0), &wsadata); #endif if (argc > 1) { @@ -97,7 +97,12 @@ int main(int argc, char *argv[]) #elif defined(HAVE_IOCTLSOCKET) ioctlsocket(sock, FIONBIO, &flag); #else +#ifdef WIN32 + u_long mode = 1; + ioctlsocket (sock, FIONBIO, &mode); +#else #error "add support for setting the socket non-blocking here" +#endif #endif /* Create a session instance diff --git a/example/simple/sftp_nonblock.c b/example/simple/sftp_nonblock.c index 82e761a..c56d15d 100644 --- a/example/simple/sftp_nonblock.c +++ b/example/simple/sftp_nonblock.c @@ -1,5 +1,5 @@ /* - * $Id: sftp_nonblock.c,v 1.14 2008/09/30 08:55:35 bagder Exp $ + * $Id: sftp_nonblock.c,v 1.15 2008/11/10 16:48:41 bagder Exp $ * * Sample showing how to do SFTP non-blocking transfers. * @@ -9,7 +9,7 @@ * "sftp 192.168.0.1 user password /tmp/secrets" */ -#include "config.h" +#include "libssh2_config.h" #include #include @@ -58,7 +58,7 @@ int main(int argc, char *argv[]) #ifdef WIN32 WSADATA wsadata; - WSAStartup(WINSOCK_VERSION, &wsadata); + WSAStartup(MAKEWORD(2,0), &wsadata); #endif if (argc > 1) { @@ -100,7 +100,12 @@ int main(int argc, char *argv[]) #elif defined(HAVE_IOCTLSOCKET) ioctlsocket(sock, FIONBIO, &flag); #else +#ifdef WIN32 + u_long mode = 1; + ioctlsocket (sock, FIONBIO, &mode); +#else #error "add support for setting the socket non-blocking here" +#endif #endif /* Create a session instance */ diff --git a/example/simple/sftp_write.c b/example/simple/sftp_write.c index d37b63f..2fe5889 100644 --- a/example/simple/sftp_write.c +++ b/example/simple/sftp_write.c @@ -1,5 +1,5 @@ /* - * $Id: sftp_write.c,v 1.8 2007/08/09 01:10:11 dfandrich Exp $ + * $Id: sftp_write.c,v 1.9 2008/11/10 16:48:41 bagder Exp $ * * Sample showing how to do SFTP write transfers. * @@ -9,7 +9,7 @@ * "sftp 192.168.0.1 user password sftp_write.c /tmp/secrets" */ -#include "config.h" +#include "libssh2_config.h" #include #include @@ -57,7 +57,7 @@ int main(int argc, char *argv[]) #ifdef WIN32 WSADATA wsadata; - WSAStartup(WINSOCK_VERSION, &wsadata); + WSAStartup(MAKEWORD(2,0), &wsadata); #endif if (argc > 1) { diff --git a/example/simple/sftp_write_nonblock.c b/example/simple/sftp_write_nonblock.c index 85787a1..7e56250 100644 --- a/example/simple/sftp_write_nonblock.c +++ b/example/simple/sftp_write_nonblock.c @@ -1,5 +1,5 @@ /* - * $Id: sftp_write_nonblock.c,v 1.11 2008/09/30 08:55:35 bagder Exp $ + * $Id: sftp_write_nonblock.c,v 1.12 2008/11/10 16:48:41 bagder Exp $ * * Sample showing how to do SFTP non-blocking write transfers. * @@ -9,7 +9,7 @@ * "sftp 192.168.0.1 user password sftp_write_nonblock.c /tmp/sftp_write_nonblock.c" */ -#include "config.h" +#include "libssh2_config.h" #include #include @@ -60,7 +60,7 @@ int main(int argc, char *argv[]) #ifdef WIN32 WSADATA wsadata; - WSAStartup(WINSOCK_VERSION, &wsadata); + WSAStartup(MAKEWORD(2,0), &wsadata); #endif if (argc > 1) { @@ -112,7 +112,12 @@ int main(int argc, char *argv[]) #elif defined(HAVE_IOCTLSOCKET) ioctlsocket(sock, FIONBIO, &flag); #else +#ifdef WIN32 + u_long mode = 1; + ioctlsocket (sock, FIONBIO, &mode); +#else #error "add support for setting the socket non-blocking here" +#endif #endif /* Create a session instance diff --git a/example/simple/sftpdir.c b/example/simple/sftpdir.c index 3d968e9..fee78ed 100644 --- a/example/simple/sftpdir.c +++ b/example/simple/sftpdir.c @@ -1,5 +1,5 @@ /* - * $Id: sftpdir.c,v 1.9 2007/08/09 01:10:11 dfandrich Exp $ + * $Id: sftpdir.c,v 1.10 2008/11/10 16:48:41 bagder Exp $ * * Sample doing an SFTP directory listing. * @@ -9,7 +9,7 @@ * "sftpdir 192.168.0.1 user password /tmp/secretdir" */ -#include "config.h" +#include "libssh2_config.h" #include #include @@ -52,7 +52,7 @@ int main(int argc, char *argv[]) #ifdef WIN32 WSADATA wsadata; - WSAStartup(WINSOCK_VERSION, &wsadata); + WSAStartup(MAKEWORD(2,0), &wsadata); #endif if (argc > 1) { diff --git a/example/simple/sftpdir_nonblock.c b/example/simple/sftpdir_nonblock.c index ff3af63..8b2d60d 100644 --- a/example/simple/sftpdir_nonblock.c +++ b/example/simple/sftpdir_nonblock.c @@ -1,5 +1,5 @@ /* - * $Id: sftpdir_nonblock.c,v 1.11 2008/09/30 08:55:35 bagder Exp $ + * $Id: sftpdir_nonblock.c,v 1.12 2008/11/10 16:48:41 bagder Exp $ * * Sample doing an SFTP directory listing. * @@ -9,7 +9,7 @@ * "sftpdir 192.168.0.1 user password /tmp/secretdir" */ -#include "config.h" +#include "libssh2_config.h" #include #include @@ -55,7 +55,7 @@ int main(int argc, char *argv[]) #ifdef WIN32 WSADATA wsadata; - WSAStartup(WINSOCK_VERSION, &wsadata); + WSAStartup(MAKEWORD(2,0), &wsadata); #endif if (argc > 1) { @@ -97,7 +97,12 @@ int main(int argc, char *argv[]) #elif defined(HAVE_IOCTLSOCKET) ioctlsocket(sock, FIONBIO, &flag); #else +#ifdef WIN32 + u_long mode = 1; + ioctlsocket (sock, FIONBIO, &mode); +#else #error "add support for setting the socket non-blocking here" +#endif #endif /* Create a session instance diff --git a/example/simple/ssh2.c b/example/simple/ssh2.c index 2e128d4..e609e65 100644 --- a/example/simple/ssh2.c +++ b/example/simple/ssh2.c @@ -1,5 +1,5 @@ /* - * $Id: ssh2.c,v 1.17 2007/08/09 01:10:11 dfandrich Exp $ + * $Id: ssh2.c,v 1.18 2008/11/10 16:48:41 bagder Exp $ * * Sample showing how to do SSH2 connect. * @@ -9,10 +9,13 @@ * "ssh2 host user password [-p|-i|-k]" */ -#include "config.h" +#include "libssh2_config.h" #include #include +#ifdef HAVE_WINDOWS_H +# include +#endif #ifdef HAVE_WINSOCK2_H # include #endif @@ -73,7 +76,7 @@ int main(int argc, char *argv[]) #ifdef WIN32 WSADATA wsadata; - WSAStartup(WINSOCK_VERSION, &wsadata); + WSAStartup(MAKEWORD(2,0), &wsadata); #endif if (argc > 1) { diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 45d463a..12b594d 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -41,6 +41,14 @@ #define LIBSSH2_LIBRARY #include "libssh2_config.h" +#ifdef HAVE_WINDOWS_H +#include +#endif + +#ifdef HAVE_WS2TCPIP_H +#include +#endif + /* The following CPP block should really only be in session.c and packet.c. However, AIX have #define's for 'events' and 'revents' and we are using those names in libssh2.h, so we need to include @@ -70,6 +78,28 @@ #include "libssh2_publickey.h" #include "libssh2_sftp.h" +/* Provide iovec / writev on WIN32 platform. */ +#ifdef WIN32 + +/* same as WSABUF */ +struct iovec { + u_long iov_len; + char *iov_base; +}; + +#define inline __inline + +static inline int writev(int sock, struct iovec *iov, int nvecs) +{ + DWORD ret; + if (WSASend(sock, (LPWSABUF)iov, nvecs, &ret, 0, NULL, NULL) == 0) { + return ret; + } + return -1; +} + +#endif /* WIN32 */ + /* Needed for struct iovec on some platforms */ #ifdef HAVE_SYS_UIO_H #include