Make example/direct_tcpip.c compile for win32

One warning from FD_SET() remains, it is also in some other examples.
This commit is contained in:
Peter Stuge 2010-01-29 20:35:24 +01:00
parent abd9bd0bbe
commit 6c543545fe

View File

@ -8,6 +8,7 @@
#ifdef HAVE_WINSOCK2_H #ifdef HAVE_WINSOCK2_H
# include <winsock2.h> # include <winsock2.h>
# include <ws2tcpip.h>
#endif #endif
#ifdef HAVE_SYS_SOCKET_H #ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h> # include <sys/socket.h>
@ -67,9 +68,12 @@ int main(int argc, char *argv[])
char buf[16384]; char buf[16384];
#ifdef WIN32 #ifdef WIN32
char sockopt;
WSADATA wsadata; WSADATA wsadata;
WSAStartup(MAKEWORD(2,0), &wsadata); WSAStartup(MAKEWORD(2,0), &wsadata);
#else
int sockopt;
#endif #endif
if (argc > 1) if (argc > 1)
@ -90,8 +94,8 @@ int main(int argc, char *argv[])
/* Connect to SSH server */ /* Connect to SSH server */
sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
if (-1 == inet_aton(server_ip, &sin.sin_addr)) { if (INADDR_NONE == (sin.sin_addr.s_addr = inet_addr(server_ip))) {
perror("inet_aton"); perror("inet_addr");
return -1; return -1;
} }
sin.sin_port = htons(22); sin.sin_port = htons(22);
@ -163,12 +167,12 @@ int main(int argc, char *argv[])
listensock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); listensock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
sin.sin_port = htons(local_listenport); sin.sin_port = htons(local_listenport);
if (-1 == inet_aton(local_listenip, &sin.sin_addr)) { if (INADDR_NONE == (sin.sin_addr.s_addr = inet_addr(local_listenip))) {
perror("inet_aton"); perror("inet_addr");
goto shutdown; goto shutdown;
} }
i = 1; sockopt = 1;
setsockopt(listensock, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i)); setsockopt(listensock, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof(sockopt));
sinlen=sizeof(sin); sinlen=sizeof(sin);
if (-1 == bind(listensock, (struct sockaddr *)&sin, sinlen)) { if (-1 == bind(listensock, (struct sockaddr *)&sin, sinlen)) {
perror("bind"); perror("bind");
@ -239,7 +243,7 @@ int main(int argc, char *argv[])
if (LIBSSH2_ERROR_EAGAIN == len) if (LIBSSH2_ERROR_EAGAIN == len)
break; break;
else if (len < 0) { else if (len < 0) {
fprintf(stderr, "libssh2_channel_read: %d", len); fprintf(stderr, "libssh2_channel_read: %d", (int)len);
goto shutdown; goto shutdown;
} }
wr = 0; wr = 0;