# Miscellaneous objects appearing in all the network utilities (not
# Pageant or PuTTYgen).
-MISC = timing callback misc version settings tree234 proxy conf
+MISC = timing callback misc version settings tree234 proxy conf be_misc
WINMISC = MISC winstore winnet winhandl cmdline windefs winmisc winproxy
+ wintime winhsock errsock
UXMISC = MISC uxstore uxsel uxnet uxpeer cmdline uxmisc uxproxy time
--- /dev/null
+/*
+ * be_misc.c: helper functions shared between main network backends.
+ */
+
+#include "putty.h"
+#include "network.h"
+
+void backend_socket_log(void *frontend, int type, SockAddr addr, int port,
+ const char *error_msg, int error_code)
+{
+ char addrbuf[256], *msg;
+
+ switch (type) {
+ case 0:
+ sk_getaddr(addr, addrbuf, lenof(addrbuf));
+ if (sk_addr_needs_port(addr)) {
+ msg = dupprintf("Connecting to %s port %d", addrbuf, port);
+ } else {
+ msg = dupprintf("Connecting to %s", addrbuf);
+ }
+ break;
+ case 1:
+ sk_getaddr(addr, addrbuf, lenof(addrbuf));
+ msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg);
+ break;
+ default:
+ msg = NULL; /* shouldn't happen, but placate optimiser */
+ break;
+ }
+
+ if (msg) {
+ logevent(frontend, msg);
+ sfree(msg);
+ }
+}
+
*/
Socket new_error_socket(const char *errmsg, Plug plug);
+/* ----------------------------------------------------------------------
+ * Functions defined outside the network code, which have to be
+ * declared in this header file rather than the main putty.h because
+ * they use types defined here.
+ */
+
+/*
+ * Exports from be_misc.c.
+ */
+void backend_socket_log(void *frontend, int type, SockAddr addr, int port,
+ const char *error_msg, int error_code);
+
#endif
const char *error_msg, int error_code)
{
Raw raw = (Raw) plug;
- char addrbuf[256], *msg;
-
- sk_getaddr(addr, addrbuf, lenof(addrbuf));
-
- if (type == 0)
- msg = dupprintf("Connecting to %s port %d", addrbuf, port);
- else
- msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg);
-
- logevent(raw->frontend, msg);
- sfree(msg);
+ backend_socket_log(raw->frontend, type, addr, port,
+ error_msg, error_code);
}
static void raw_check_close(Raw raw)
const char *error_msg, int error_code)
{
Rlogin rlogin = (Rlogin) plug;
- char addrbuf[256], *msg;
-
- sk_getaddr(addr, addrbuf, lenof(addrbuf));
-
- if (type == 0)
- msg = dupprintf("Connecting to %s port %d", addrbuf, port);
- else
- msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg);
-
- logevent(rlogin->frontend, msg);
- sfree(msg);
+ backend_socket_log(rlogin->frontend, type, addr, port,
+ error_msg, error_code);
}
static int rlogin_closing(Plug plug, const char *error_msg, int error_code,
const char *error_msg, int error_code)
{
Ssh ssh = (Ssh) plug;
- char addrbuf[256], *msg;
- if (ssh->attempting_connshare) {
- /*
- * While we're attempting connection sharing, don't loudly log
- * everything that happens. Real TCP connections need to be
- * logged when we _start_ trying to connect, because it might
- * be ages before they respond if something goes wrong; but
- * connection sharing is local and quick to respond, and it's
- * sufficient to simply wait and see whether it worked
- * afterwards.
- */
- } else {
- sk_getaddr(addr, addrbuf, lenof(addrbuf));
-
- if (type == 0) {
- if (sk_addr_needs_port(addr)) {
- msg = dupprintf("Connecting to %s port %d", addrbuf, port);
- } else {
- msg = dupprintf("Connecting to %s", addrbuf);
- }
- } else {
- msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg);
- }
+ /*
+ * While we're attempting connection sharing, don't loudly log
+ * everything that happens. Real TCP connections need to be logged
+ * when we _start_ trying to connect, because it might be ages
+ * before they respond if something goes wrong; but connection
+ * sharing is local and quick to respond, and it's sufficient to
+ * simply wait and see whether it worked afterwards.
+ */
- logevent(msg);
- sfree(msg);
- }
+ if (!ssh->attempting_connshare)
+ backend_socket_log(ssh->frontend, type, addr, port,
+ error_msg, error_code);
}
void ssh_connshare_log(Ssh ssh, int event, const char *logtext,
const char *error_msg, int error_code)
{
Telnet telnet = (Telnet) plug;
- char addrbuf[256], *msg;
-
- sk_getaddr(addr, addrbuf, lenof(addrbuf));
-
- if (type == 0)
- msg = dupprintf("Connecting to %s port %d", addrbuf, port);
- else
- msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg);
-
- logevent(telnet->frontend, msg);
- sfree(msg);
+ backend_socket_log(telnet->frontend, type, addr, port,
+ error_msg, error_code);
}
static int telnet_closing(Plug plug, const char *error_msg, int error_code,