projects
/
u
/
mdw
/
putty
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Enable protocol prefix on [user@]host argument in Plink
[u/mdw/putty]
/
telnet.c
diff --git
a/telnet.c
b/telnet.c
index
1b83a31
..
4fb39c6
100644
(file)
--- a/
telnet.c
+++ b/
telnet.c
@@
-1,7
+1,13
@@
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
+#ifndef AUTO_WINSOCK
+#ifdef WINSOCK_TWO
+#include <winsock2.h>
+#else
#include <winsock.h>
#include <winsock.h>
+#endif
+#endif
#include "putty.h"
#include "putty.h"
@@
-552,7
+558,7
@@
static char *telnet_init (HWND hwnd, char *host, int port, char **realhost) {
default: return "connect(): unknown error";
}
default: return "connect(): unknown error";
}
- if (WSAAsyncSelect (s, hwnd, WM_NETEVENT, FD_READ |
+ if (
hwnd &&
WSAAsyncSelect (s, hwnd, WM_NETEVENT, FD_READ |
FD_WRITE | FD_OOB | FD_CLOSE) == SOCKET_ERROR)
switch (WSAGetLastError()) {
case WSAENETDOWN: return "Network is down";
FD_WRITE | FD_OOB | FD_CLOSE) == SOCKET_ERROR)
switch (WSAGetLastError()) {
case WSAENETDOWN: return "Network is down";
@@
-583,6
+589,12
@@
static char *telnet_init (HWND hwnd, char *host, int port, char **realhost) {
* Set up SYNCH state.
*/
in_synch = FALSE;
* Set up SYNCH state.
*/
in_synch = FALSE;
+
+ /*
+ * We have no pre-session phase.
+ */
+ begin_session();
+
return NULL;
}
return NULL;
}
@@
-608,8
+620,11
@@
static int telnet_msg (WPARAM wParam, LPARAM lParam) {
if (s == INVALID_SOCKET)
return 1;
if (s == INVALID_SOCKET)
return 1;
- if (WSAGETSELECTERROR(lParam) != 0)
+ if (WSAGETSELECTERROR(lParam) != 0) {
+ closesocket(s);
+ s = INVALID_SOCKET;
return -WSAGETSELECTERROR(lParam);
return -WSAGETSELECTERROR(lParam);
+ }
switch (WSAGETSELECTEVENT(lParam)) {
case FD_READ:
switch (WSAGETSELECTEVENT(lParam)) {
case FD_READ:
@@
-625,13
+640,15
@@
static int telnet_msg (WPARAM wParam, LPARAM lParam) {
ret = recv(s, buf, sizeof(buf), 0);
if (ret < 0 && WSAGetLastError() == WSAEWOULDBLOCK)
return 1;
ret = recv(s, buf, sizeof(buf), 0);
if (ret < 0 && WSAGetLastError() == WSAEWOULDBLOCK)
return 1;
- if (ret < 0) /* any _other_ error */
+ if (ret < 0) { /* any _other_ error */
+ closesocket(s);
+ s = INVALID_SOCKET;
return -10000-WSAGetLastError();
return -10000-WSAGetLastError();
+ }
if (ret == 0) {
s = INVALID_SOCKET;
return 0;
}
if (ret == 0) {
s = INVALID_SOCKET;
return 0;
}
-
do_telnet_read (buf, ret);
} while (in_synch);
}
do_telnet_read (buf, ret);
} while (in_synch);
}
@@
-733,10
+750,17
@@
static void telnet_special (Telnet_Special code) {
}
}
}
}
+static SOCKET telnet_socket(void) { return s; }
+
+static int telnet_sendok(void) { return 1; }
+
Backend telnet_backend = {
telnet_init,
telnet_msg,
telnet_send,
telnet_size,
Backend telnet_backend = {
telnet_init,
telnet_msg,
telnet_send,
telnet_size,
- telnet_special
+ telnet_special,
+ telnet_socket,
+ telnet_sendok,
+ 23
};
};