From: simon Date: Wed, 30 Oct 2002 17:57:31 +0000 (+0000) Subject: More preparatory work: remove the include from lots of X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/commitdiff_plain/68a49acbf3f96fbbbc385620655dcb577e62c328 More preparatory work: remove the include from lots of source files in which it's no longer required (it was previously required in anything that included , 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 --- diff --git a/be_all.c b/be_all.c index fc0755ae..96dac532 100644 --- a/be_all.c +++ b/be_all.c @@ -3,7 +3,6 @@ * including ssh. */ -#include #include #include "putty.h" diff --git a/cmdline.c b/cmdline.c index 23f0655c..e3a0c340 100644 --- a/cmdline.c +++ b/cmdline.c @@ -1,4 +1,3 @@ -#include #include #include #include diff --git a/network.h b/network.h index 245391d1..8d5ba1ef 100644 --- 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 **********/ /* diff --git a/portfwd.c b/portfwd.c index a153d086..16f001ab 100644 --- a/portfwd.c +++ b/portfwd.c @@ -1,4 +1,3 @@ -#include #include #include diff --git a/proxy.c b/proxy.c index a8960809..0760e7e8 100644 --- a/proxy.c +++ b/proxy.c @@ -5,8 +5,6 @@ * code and the higher level backend. */ -#include - #include #include #include @@ -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 049b8518..7a07ea80 100644 --- a/raw.c +++ b/raw.c @@ -1,4 +1,3 @@ -#include #include #include diff --git a/rlogin.c b/rlogin.c index 7b556048..942a07ec 100644 --- a/rlogin.c +++ b/rlogin.c @@ -1,4 +1,3 @@ -#include #include #include #include @@ -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 3cbee47e..3534d081 100644 --- a/ssh.c +++ b/ssh.c @@ -1,4 +1,3 @@ -#include #include #include #include @@ -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 8246e25d..efd96244 100644 --- 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 } /* diff --git a/sshdes.c b/sshdes.c index d8b3369d..5026d2ca 100644 --- 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" diff --git a/telnet.c b/telnet.c index 1f1a89e3..18c7d0e4 100644 --- a/telnet.c +++ b/telnet.c @@ -1,4 +1,3 @@ -#include #include #include @@ -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; } diff --git a/unix/unix.h b/unix/unix.h index 7b0bb4be..f31de3ce 100644 --- a/unix/unix.h +++ b/unix/unix.h @@ -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 diff --git a/winnet.c b/winnet.c index 4ea29038..430a47bb 100644 --- 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; +} diff --git a/x11fwd.c b/x11fwd.c index 033184b2..c6e36378 100644 --- a/x11fwd.c +++ b/x11fwd.c @@ -1,4 +1,3 @@ -#include #include #include