first part of win32 patches
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@141 7dcaeef0-15fb-0310-b436-a5af3365683c
Этот коммит содержится в:
родитель
5029fe9d74
Коммит
29997022c8
@ -21,7 +21,12 @@ MA 02111-1307, USA. */
|
||||
#ifndef _LIBSSH_H
|
||||
#define _LIBSSH_H
|
||||
#include <unistd.h>
|
||||
#ifndef _WIN32
|
||||
#include <sys/select.h> /* for fd_set * */
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
#include <inttypes.h>
|
||||
|
||||
#define LIBSSH_VERSION "libssh-0.2"
|
||||
@ -45,6 +50,13 @@ typedef uint16_t u16;
|
||||
typedef uint64_t u64;
|
||||
typedef uint8_t u8;
|
||||
|
||||
/* Socket type */
|
||||
#ifdef _WIN32
|
||||
#define socket_t SOCKET
|
||||
#else
|
||||
typedef int socket_t;
|
||||
#endif
|
||||
|
||||
/* the offsets of methods */
|
||||
#define SSH_KEX 0
|
||||
#define SSH_HOSTKEYS 1
|
||||
@ -110,7 +122,7 @@ void ssh_set_verbosity(int num);
|
||||
/* session.c */
|
||||
SSH_SESSION *ssh_new();
|
||||
void ssh_set_options(SSH_SESSION *session, SSH_OPTIONS *options);
|
||||
int ssh_get_fd(SSH_SESSION *session);
|
||||
socket_t ssh_get_fd(SSH_SESSION *session);
|
||||
void ssh_silent_disconnect(SSH_SESSION *session);
|
||||
int ssh_get_version(SSH_SESSION *session);
|
||||
void ssh_set_fd_toread(SSH_SESSION *session);
|
||||
|
@ -25,7 +25,6 @@ MA 02111-1307, USA. */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <netdb.h>
|
||||
|
||||
/** defgroup ssh_auth
|
||||
* \brief functions to authenticate
|
||||
*/
|
||||
|
@ -22,7 +22,6 @@ MA 02111-1307, USA. */
|
||||
#include "libssh/priv.h"
|
||||
#include "libssh/ssh1.h"
|
||||
#include <string.h>
|
||||
#include <netdb.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
|
@ -22,10 +22,10 @@ MA 02111-1307, USA. */
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include "libssh/priv.h"
|
||||
#include "libssh/ssh2.h"
|
||||
|
@ -22,10 +22,9 @@ MA 02111-1307, USA. */
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <netdb.h>
|
||||
#include "libssh/priv.h"
|
||||
#include "libssh/ssh1.h"
|
||||
|
||||
|
@ -20,17 +20,21 @@ along with the SSH Library; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA. */
|
||||
|
||||
#include <netdb.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef _WIN32
|
||||
#define _WIN32_WINNT 0x0501 //getaddrinfo, freeaddrinfo, getnameinfo
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#else
|
||||
#include <netdb.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/time.h>
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#include "libssh/priv.h"
|
||||
|
||||
@ -42,12 +46,23 @@ MA 02111-1307, USA. */
|
||||
#error "Your system must have getaddrinfo()"
|
||||
#endif
|
||||
|
||||
static void sock_set_nonblocking(int sock) {
|
||||
#ifndef _WIN32
|
||||
static void sock_set_nonblocking(socket_t sock) {
|
||||
fcntl(sock,F_SETFL,O_NONBLOCK);
|
||||
}
|
||||
static void sock_set_blocking(int sock){
|
||||
static void sock_set_blocking(socket_t sock){
|
||||
fcntl(sock,F_SETFL,0);
|
||||
}
|
||||
#else
|
||||
static void sock_set_nonblocking(socket_t sock) {
|
||||
u_long nonblocking = 1;
|
||||
ioctlsocket(sock, FIONBIO, &nonblocking);
|
||||
}
|
||||
static void sock_set_blocking(socket_t sock){
|
||||
u_long nonblocking = 0;
|
||||
ioctlsocket(sock, FIONBIO, &nonblocking);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int getai(const char *host, int port, struct addrinfo **ai)
|
||||
{
|
||||
@ -69,7 +84,7 @@ static int getai(const char *host, int port, struct addrinfo **ai)
|
||||
}
|
||||
|
||||
int ssh_connect_ai_timeout(SSH_SESSION *session, const char *host, int port, struct addrinfo *ai,
|
||||
long timeout, long usec,int s)
|
||||
long timeout, long usec,socket_t s)
|
||||
{
|
||||
struct timeval to;
|
||||
fd_set set;
|
||||
@ -94,6 +109,7 @@ int ssh_connect_ai_timeout(SSH_SESSION *session, const char *host, int port, str
|
||||
close(s);
|
||||
return -1;
|
||||
}
|
||||
ret = 0;
|
||||
/* get connect(2) return code. zero means no error */
|
||||
getsockopt(s,SOL_SOCKET,SO_ERROR,&ret,&len);
|
||||
if (ret!=0){
|
||||
@ -111,9 +127,9 @@ int ssh_connect_ai_timeout(SSH_SESSION *session, const char *host, int port, str
|
||||
/* specified by its IP address or hostname. */
|
||||
/* output is the file descriptor, <0 if failed. */
|
||||
|
||||
int ssh_connect_host(SSH_SESSION *session, const char *host, const char
|
||||
socket_t ssh_connect_host(SSH_SESSION *session, const char *host, const char
|
||||
*bind_addr, int port,long timeout, long usec){
|
||||
int s=-1;
|
||||
socket_t s=-1;
|
||||
int my_errno;
|
||||
struct addrinfo *ai, *ai2;
|
||||
|
||||
@ -239,7 +255,7 @@ int ssh_fd_poll(SSH_SESSION *session, int *write, int *except){
|
||||
* \warning libssh is not threadsafe. That means that if a signal is caught during the processing
|
||||
* of this function, you cannot call ssh functions on sessions that are busy with ssh_select()
|
||||
*/
|
||||
int ssh_select(CHANNEL **channels,CHANNEL **outchannels, int maxfd, fd_set *readfds, struct timeval *timeout){
|
||||
int ssh_select(CHANNEL **channels,CHANNEL **outchannels, socket_t maxfd, fd_set *readfds, struct timeval *timeout){
|
||||
struct timeval zerotime;
|
||||
fd_set localset,localset2;
|
||||
int rep;
|
||||
|
@ -24,6 +24,7 @@ MA 02111-1307, USA. */
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#ifdef OPENSSL_CRYPTO
|
||||
#include <openssl/blowfish.h>
|
||||
@ -31,7 +32,6 @@ MA 02111-1307, USA. */
|
||||
#include <openssl/hmac.h>
|
||||
#endif
|
||||
|
||||
#include <netdb.h>
|
||||
#include "libssh/priv.h"
|
||||
#include "libssh/crypto.h"
|
||||
|
||||
|
@ -37,9 +37,9 @@ MA 02111-1307, USA. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <netdb.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <netdb.h>
|
||||
|
||||
#include "libssh/priv.h"
|
||||
#include "libssh/crypto.h"
|
||||
|
||||
|
@ -22,7 +22,6 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA. */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <netinet/in.h>
|
||||
#ifdef HAVE_LIBCRYPTO
|
||||
#include <openssl/dsa.h>
|
||||
#include <openssl/rsa.h>
|
||||
|
@ -26,13 +26,14 @@ MA 02111-1307, USA. */
|
||||
* functions to handle it (or use the default handlers if she doesn't know what to
|
||||
* do */
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <netdb.h>
|
||||
#include "libssh/libssh.h"
|
||||
#include "libssh/priv.h"
|
||||
#include "libssh/server.h"
|
||||
#include "libssh/ssh2.h"
|
||||
#include <netdb.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
static SSH_MESSAGE *message_new(SSH_SESSION *session){
|
||||
SSH_MESSAGE *msg=session->ssh_message;
|
||||
|
@ -24,10 +24,10 @@ MA 02111-1307, USA. */
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <netdb.h>
|
||||
#include "libssh/priv.h"
|
||||
#include "libssh/ssh2.h"
|
||||
#include "libssh/ssh1.h"
|
||||
#include <netdb.h>
|
||||
#include <errno.h>
|
||||
#include "libssh/crypto.h"
|
||||
|
||||
|
@ -25,10 +25,22 @@ MA 02111-1307, USA. */
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#define SOCKOPT_TYPE_ARG4 char
|
||||
|
||||
/* We need to provide hstrerror. Not we can't call the parameter h_errno because it's #defined */
|
||||
inline char* hstrerror(int h_errno_val) {
|
||||
static char text[50];
|
||||
snprintf(text,sizeof(text),"gethostbyname error %d\n", h_errno_val);
|
||||
return text;
|
||||
}
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#define SOCKOPT_TYPE_ARG4 int
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@ -36,10 +48,12 @@ MA 02111-1307, USA. */
|
||||
#include "libssh/libssh.h"
|
||||
#include "libssh/server.h"
|
||||
#include "libssh/ssh2.h"
|
||||
static int bind_socket(SSH_BIND *ssh_bind,char *hostname, int port) {
|
||||
|
||||
// TODO: must use getaddrinfo
|
||||
static socket_t bind_socket(SSH_BIND *ssh_bind,char *hostname, int port) {
|
||||
struct sockaddr_in myaddr;
|
||||
int opt = 1;
|
||||
int s = socket(PF_INET, SOCK_STREAM, 0);
|
||||
socket_t s = socket(PF_INET, SOCK_STREAM, 0);
|
||||
struct hostent *hp=NULL;
|
||||
#ifdef HAVE_GETHOSTBYNAME
|
||||
hp=gethostbyname(hostname);
|
||||
|
@ -133,7 +133,8 @@ void ssh_set_blocking(SSH_SESSION *session,int blocking){
|
||||
* \return file descriptor of the connection, or -1 if it is
|
||||
* not connected
|
||||
*/
|
||||
int ssh_get_fd(SSH_SESSION *session){
|
||||
|
||||
socket_t ssh_get_fd(SSH_SESSION *session){
|
||||
return ssh_socket_get_fd(session->socket);
|
||||
}
|
||||
|
||||
|
@ -18,15 +18,17 @@ You should have received a copy of the GNU Lesser General Public License
|
||||
along with the SSH Library; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA. */
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <netdb.h>
|
||||
#include "libssh/libssh.h"
|
||||
#include "libssh/sftp.h"
|
||||
#include "libssh/ssh2.h"
|
||||
#include "libssh/priv.h"
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
SFTP_CLIENT_MESSAGE *sftp_get_client_message(SFTP_SESSION *sftp){
|
||||
SFTP_PACKET *packet=sftp_packet_read(sftp);
|
||||
|
@ -19,20 +19,23 @@
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA. */
|
||||
#include "libssh/priv.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#ifdef _WIN_32
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#include "libssh/priv.h"
|
||||
|
||||
struct socket {
|
||||
int fd;
|
||||
socket_t fd;
|
||||
int last_errno;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* \internal
|
||||
* \brief creates a new Socket object
|
||||
@ -48,6 +51,7 @@ struct socket *ssh_socket_new(){
|
||||
* \brief Deletes a socket object
|
||||
*/
|
||||
void ssh_socket_free(struct socket *s){
|
||||
ssh_socket_close(s);
|
||||
free(s);
|
||||
}
|
||||
|
||||
@ -58,10 +62,11 @@ void ssh_socket_close(struct socket *s){
|
||||
if(ssh_socket_is_open(s)){
|
||||
#ifdef _WIN_32
|
||||
closesocket(s->fd);
|
||||
s->last_errno=WSAGetLastError();
|
||||
#else
|
||||
close(s->fd);
|
||||
#endif
|
||||
s->last_errno=errno;
|
||||
#endif
|
||||
s->fd=-1;
|
||||
}
|
||||
}
|
||||
@ -69,14 +74,14 @@ void ssh_socket_close(struct socket *s){
|
||||
/* \internal
|
||||
* \brief sets the file descriptor of the socket
|
||||
*/
|
||||
void ssh_socket_set_fd(struct socket *s, int fd){
|
||||
void ssh_socket_set_fd(struct socket *s, socket_t fd){
|
||||
s->fd=fd;
|
||||
}
|
||||
|
||||
/* \internal
|
||||
* \brief returns the file descriptor of the socket
|
||||
*/
|
||||
int ssh_socket_get_fd(struct socket *s){
|
||||
socket_t ssh_socket_get_fd(struct socket *s){
|
||||
return s->fd;
|
||||
}
|
||||
|
||||
@ -92,7 +97,11 @@ int ssh_socket_is_open(struct socket *s){
|
||||
*/
|
||||
int ssh_socket_read(struct socket *s, void *buffer, int len){
|
||||
int r=recv(s->fd,buffer,len,0);
|
||||
s->last_errno=errno;
|
||||
#ifndef _WIN32
|
||||
s->last_errno=errno;
|
||||
#else
|
||||
s->last_errno=WSAGetLastError();
|
||||
#endif
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -101,7 +110,12 @@ int ssh_socket_read(struct socket *s, void *buffer, int len){
|
||||
*/
|
||||
int ssh_socket_write(struct socket *s,const void *buffer, int len){
|
||||
int w=send(s->fd,buffer,len,0);
|
||||
s->last_errno=errno;
|
||||
#ifndef _WIN32
|
||||
s->last_errno=errno;
|
||||
#else
|
||||
s->last_errno=WSAGetLastError();
|
||||
#endif
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
|
@ -21,9 +21,9 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA. */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <netdb.h>
|
||||
#include "libssh/priv.h"
|
||||
|
||||
STRING *string_new(unsigned int size){
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user