More preparatory work: remove the <windows.h> include from lots of
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Wed, 30 Oct 2002 17:57:31 +0000 (17:57 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Wed, 30 Oct 2002 17:57:31 +0000 (17:57 +0000)
source files in which it's no longer required (it was previously
required in anything that included <putty.h>, but not any more).
Also moved a couple of stray bits of exposed WinSock back into
winnet.c (getservbyname from ssh.c and AF_INET from proxy.c).

git-svn-id: svn://svn.tartarus.org/sgt/putty@2160 cda61777-01e9-0310-a592-d414129be87e

14 files changed:
be_all.c
cmdline.c
network.h
portfwd.c
proxy.c
raw.c
rlogin.c
ssh.c
sshbn.c
sshdes.c
telnet.c
unix/unix.h
winnet.c
x11fwd.c

index fc0755a..96dac53 100644 (file)
--- a/be_all.c
+++ b/be_all.c
@@ -3,7 +3,6 @@
  * including ssh.
  */
 
-#include <windows.h>
 #include <stdio.h>
 #include "putty.h"
 
index 23f0655..e3a0c34 100644 (file)
--- a/cmdline.c
+++ b/cmdline.c
@@ -1,4 +1,3 @@
-#include <windows.h>
 #include <stdio.h>
 #include <assert.h>
 #include <stdlib.h>
index 245391d..8d5ba1e 100644 (file)
--- a/network.h
+++ b/network.h
@@ -76,6 +76,7 @@ void sk_cleanup(void);                       /* called just before program exit */
 
 SockAddr sk_namelookup(char *host, char **canonicalname);
 void sk_getaddr(SockAddr addr, char *buf, int buflen);
+enum { ADDRTYPE_IPV4, ADDRTYPE_IPV6 };
 int sk_addrtype(SockAddr addr);
 void sk_addrcopy(SockAddr addr, char *buf);
 void sk_addr_free(SockAddr addr);
@@ -143,6 +144,15 @@ char *sk_addr_error(SockAddr addr);
  */
 void net_pending_errors(void);
 
+/*
+ * Simple wrapper on getservbyname(), needed by ssh.c. Returns the
+ * port number, in host byte order (suitable for printf and so on).
+ * Returns 0 on failure. Any platform not supporting getservbyname
+ * can just return 0 - this function is not required to handle
+ * numeric port specifications.
+ */
+int net_service_lookup(char *service);
+
 /********** SSL stuff **********/
 
 /*
index a153d08..16f001a 100644 (file)
--- a/portfwd.c
+++ b/portfwd.c
@@ -1,4 +1,3 @@
-#include <windows.h>
 #include <stdio.h>
 #include <stdlib.h>
 
diff --git a/proxy.c b/proxy.c
index a896080..0760e7e 100644 (file)
--- a/proxy.c
+++ b/proxy.c
@@ -5,8 +5,6 @@
  * code and the higher level backend.
  */
 
-#include <windows.h>
-
 #include <assert.h>
 #include <ctype.h>
 #include <string.h>
@@ -155,7 +153,7 @@ static void sk_proxy_set_frozen (Socket s, int is_frozen)
         * so we have to check each time.
         */
         while (!ps->freeze && bufchain_size(&ps->pending_input_data) > 0) {
-           char * data;
+           void *data;
            int len;
            bufchain_prefix(&ps->pending_input_data, &data, &len);
            plug_receive(ps->plug, 0, data, len);
@@ -641,7 +639,7 @@ int proxy_socks4_negotiate (Proxy_Socket p, int change)
        int length;
        char * command;
 
-       if (sk_addrtype(p->remote_addr) != AF_INET) {
+       if (sk_addrtype(p->remote_addr) != ADDRTYPE_IPV4) {
            plug_closing(p->plug, "Proxy error: SOCKS version 4 does"
                         " not support IPv6", PROXY_ERROR_GENERAL, 0);
            return 1;
@@ -931,7 +929,7 @@ int proxy_socks5_negotiate (Proxy_Socket p, int change)
            char command[22];
            int len;
 
-           if (sk_addrtype(p->remote_addr) == AF_INET) {
+           if (sk_addrtype(p->remote_addr) == ADDRTYPE_IPV6) {
                len = 10;
                command[3] = 1; /* IPv4 */
            } else {
diff --git a/raw.c b/raw.c
index 049b851..7a07ea8 100644 (file)
--- a/raw.c
+++ b/raw.c
@@ -1,4 +1,3 @@
-#include <windows.h>
 #include <stdio.h>
 #include <stdlib.h>
 
index 7b55604..942a07e 100644 (file)
--- a/rlogin.c
+++ b/rlogin.c
@@ -1,4 +1,3 @@
-#include <windows.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
@@ -234,7 +233,7 @@ static Socket rlogin_socket(void *handle)
 
 static int rlogin_sendok(void *handle)
 {
-    Rlogin rlogin = (Rlogin) handle;
+    /* Rlogin rlogin = (Rlogin) handle; */
     return 1;
 }
 
@@ -246,7 +245,7 @@ static void rlogin_unthrottle(void *handle, int backlog)
 
 static int rlogin_ldisc(void *handle, int option)
 {
-    Rlogin rlogin = (Rlogin) handle;
+    /* Rlogin rlogin = (Rlogin) handle; */
     return 0;
 }
 
@@ -262,7 +261,7 @@ static void rlogin_provide_logctx(void *handle, void *logctx)
 
 static int rlogin_exitcode(void *handle)
 {
-    Rlogin rlogin = (Rlogin) handle;
+    /* Rlogin rlogin = (Rlogin) handle; */
     /* If we ever implement RSH, we'll probably need to do this properly */
     return 0;
 }
diff --git a/ssh.c b/ssh.c
index 3cbee47..3534d08 100644 (file)
--- a/ssh.c
+++ b/ssh.c
@@ -1,4 +1,3 @@
-#include <windows.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
@@ -3072,7 +3071,6 @@ static void ssh1_protocol(Ssh ssh, unsigned char *in, int inlen, int ispkt)
        int sport,dport,sserv,dserv;
        char sports[256], dports[256], host[256];
        char buf[1024];
-       struct servent *se;
 
        ssh->rportfwds = newtree234(ssh_rportcmp_ssh1);
         /* Add port forwardings. */
@@ -3100,10 +3098,8 @@ static void ssh1_protocol(Ssh ssh, unsigned char *in, int inlen, int ispkt)
            dserv = 0;
            if (dport == 0) {
                dserv = 1;
-               se = getservbyname(dports, NULL);
-               if (se != NULL) {
-                   dport = ntohs(se->s_port);
-               } else {
+               dport = net_service_lookup(dports);
+               if (!dport) {
                    sprintf(buf,
                            "Service lookup failed for destination port \"%s\"",
                            dports);
@@ -3114,10 +3110,8 @@ static void ssh1_protocol(Ssh ssh, unsigned char *in, int inlen, int ispkt)
            sserv = 0;
            if (sport == 0) {
                sserv = 1;
-               se = getservbyname(sports, NULL);
-               if (se != NULL) {
-                   sport = ntohs(se->s_port);
-               } else {
+               sport = net_service_lookup(sports);
+               if (!sport) {
                    sprintf(buf,
                            "Service lookup failed for source port \"%s\"",
                            sports);
@@ -3129,10 +3123,10 @@ static void ssh1_protocol(Ssh ssh, unsigned char *in, int inlen, int ispkt)
                    pfd_addforward(host, dport, sport, ssh);
                    sprintf(buf, "Local port %.*s%.*s%d%.*s forwarding to"
                            " %s:%.*s%.*s%d%.*s",
-                           sserv ? strlen(sports) : 0, sports,
+                           (int)(sserv ? strlen(sports) : 0), sports,
                            sserv, "(", sport, sserv, ")",
                            host,
-                           dserv ? strlen(dports) : 0, dports,
+                           (int)(dserv ? strlen(dports) : 0), dports,
                            dserv, "(", dport, dserv, ")");
                    logevent(buf);
                } else {
@@ -3149,10 +3143,10 @@ static void ssh1_protocol(Ssh ssh, unsigned char *in, int inlen, int ispkt)
                    } else {
                        sprintf(buf, "Requesting remote port %.*s%.*s%d%.*s"
                                " forward to %s:%.*s%.*s%d%.*s",
-                           sserv ? strlen(sports) : 0, sports,
+                           (int)(sserv ? strlen(sports) : 0), sports,
                            sserv, "(", sport, sserv, ")",
                            host,
-                           dserv ? strlen(dports) : 0, dports,
+                           (int)(dserv ? strlen(dports) : 0), dports,
                            dserv, "(", dport, dserv, ")");
                        logevent(buf);
                        send_packet(ssh, SSH1_CMSG_PORT_FORWARD_REQUEST,
@@ -3412,7 +3406,6 @@ static void ssh1_protocol(Ssh ssh, unsigned char *in, int inlen, int ispkt)
 
            } else if (ssh->pktin.type == SSH1_MSG_CHANNEL_OPEN_FAILURE) {
                unsigned int remoteid = GET_32BIT(ssh->pktin.body);
-               unsigned int localid = GET_32BIT(ssh->pktin.body+4);
                struct ssh_channel *c;
 
                c = find234(ssh->channels, &remoteid, ssh_channelfind);
@@ -5120,7 +5113,6 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, int ispkt)
        int sport,dport,sserv,dserv;
        char sports[256], dports[256], host[256];
        char buf[1024];
-       struct servent *se;
 
        ssh->rportfwds = newtree234(ssh_rportcmp_ssh2);
         /* Add port forwardings. */
@@ -5148,10 +5140,8 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, int ispkt)
            dserv = 0;
            if (dport == 0) {
                dserv = 1;
-               se = getservbyname(dports, NULL);
-               if (se != NULL) {
-                   dport = ntohs(se->s_port);
-               } else {
+               dport = net_service_lookup(dports);
+               if (!dport) {
                    sprintf(buf,
                            "Service lookup failed for destination port \"%s\"",
                            dports);
@@ -5162,10 +5152,8 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, int ispkt)
            sserv = 0;
            if (sport == 0) {
                sserv = 1;
-               se = getservbyname(sports, NULL);
-               if (se != NULL) {
-                   sport = ntohs(se->s_port);
-               } else {
+               sport = net_service_lookup(sports);
+               if (!sport) {
                    sprintf(buf,
                            "Service lookup failed for source port \"%s\"",
                            sports);
@@ -5177,10 +5165,10 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, int ispkt)
                    pfd_addforward(host, dport, sport, ssh);
                    sprintf(buf, "Local port %.*s%.*s%d%.*s forwarding to"
                            " %s:%.*s%.*s%d%.*s",
-                           sserv ? strlen(sports) : 0, sports,
+                           (int)(sserv ? strlen(sports) : 0), sports,
                            sserv, "(", sport, sserv, ")",
                            host,
-                           dserv ? strlen(dports) : 0, dports,
+                           (int)(dserv ? strlen(dports) : 0), dports,
                            dserv, "(", dport, dserv, ")");
                    logevent(buf);
                } else {
@@ -5198,10 +5186,10 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, int ispkt)
                    } else {
                        sprintf(buf, "Requesting remote port %.*s%.*s%d%.*s"
                                " forward to %s:%.*s%.*s%d%.*s",
-                           sserv ? strlen(sports) : 0, sports,
+                           (int)(sserv ? strlen(sports) : 0), sports,
                            sserv, "(", sport, sserv, ")",
                            host,
-                           dserv ? strlen(dports) : 0, dports,
+                           (int)(dserv ? strlen(dports) : 0), dports,
                            dserv, "(", dport, dserv, ")");
                        logevent(buf);
                        ssh2_pkt_init(ssh, SSH2_MSG_GLOBAL_REQUEST);
diff --git a/sshbn.c b/sshbn.c
index 8246e25..efd9624 100644 (file)
--- a/sshbn.c
+++ b/sshbn.c
@@ -799,6 +799,7 @@ unsigned short bignum_mod_short(Bignum number, unsigned short modulus)
 
 void diagbn(char *prefix, Bignum md)
 {
+#ifdef DEBUG
     int i, nibbles, morenibbles;
     static const char hex[] = "0123456789ABCDEF";
 
@@ -816,6 +817,7 @@ void diagbn(char *prefix, Bignum md)
 
     if (prefix)
        debug(("\n"));
+#endif
 }
 
 /*
index d8b3369..5026d2c 100644 (file)
--- a/sshdes.c
+++ b/sshdes.c
@@ -908,7 +908,7 @@ static const struct ssh2_cipher ssh_3des_ssh2 = {
  * only people to do so, so we sigh and implement it anyway.
  */
 static const struct ssh2_cipher ssh_des_ssh2 = {
-    des3_make_context, des3_free_context, des3_iv, des_key,
+    des_make_context, des3_free_context, des3_iv, des_key,
     des_ssh2_encrypt_blk, des_ssh2_decrypt_blk,
     "des-cbc",
     8, 56, "single-DES"
index 1f1a89e..18c7d0e 100644 (file)
--- a/telnet.c
+++ b/telnet.c
@@ -1,4 +1,3 @@
-#include <windows.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -890,7 +889,7 @@ static Socket telnet_socket(void *handle)
 
 static int telnet_sendok(void *handle)
 {
-    Telnet telnet = (Telnet) handle;
+    /* Telnet telnet = (Telnet) handle; */
     return 1;
 }
 
@@ -923,7 +922,7 @@ static void telnet_provide_logctx(void *handle, void *logctx)
 
 static int telnet_exitcode(void *handle)
 {
-    Telnet telnet = (Telnet) handle;
+    /* Telnet telnet = (Telnet) handle; */
     /* Telnet doesn't transmit exit codes back to the client */
     return 0;
 }
index 7b0bb4b..f31de3c 100644 (file)
@@ -42,4 +42,7 @@ void provide_xrm_string(char *string);
 
 #define DEFAULT_CODEPAGE 0            /* FIXME: no idea how to do this */
 
+#define strnicmp strncasecmp
+#define stricmp strcasecmp
+
 #endif
index 4ea2903..430a47b 100644 (file)
--- a/winnet.c
+++ b/winnet.c
@@ -370,7 +370,7 @@ void sk_getaddr(SockAddr addr, char *buf, int buflen)
 
 int sk_addrtype(SockAddr addr)
 {
-    return addr->family;
+    return (addr->family == AF_INET ? ADDRTYPE_IPV4 : ADDRTYPE_IPV6);
 }
 
 void sk_addrcopy(SockAddr addr, char *buf)
@@ -1138,3 +1138,13 @@ SOCKET next_socket(int *state)
     Actual_Socket s = index234(sktree, (*state)++);
     return s ? s->s : INVALID_SOCKET;
 }
+
+int net_service_lookup(char *service)
+{
+    struct servent *se;
+    se = getservbyname(service, NULL);
+    if (se != NULL)
+       return ntohs(se->s_port);
+    else
+       return 0;
+}
index 033184b..c6e3637 100644 (file)
--- a/x11fwd.c
+++ b/x11fwd.c
@@ -1,4 +1,3 @@
-#include <windows.h>
 #include <stdio.h>
 #include <stdlib.h>