diff -ur dircproxy-1.0.2.orig/conf/dircproxyrc dircproxy-1.0.2/conf/dircproxyrc --- dircproxy-1.0.2.orig/conf/dircproxyrc Fri Dec 21 20:59:25 2001 +++ dircproxy-1.0.2/conf/dircproxyrc Fri Feb 1 15:57:09 2002 @@ -748,6 +748,17 @@ # #dcc_tunnel_outgoing "none" +# dcc_rewrite_source +# When the client is behind a masquerading router, his source address +# given in DCC requests might be wrong. If set, this IP address is +# changed in *outgoing* requests to the address from which we got +# the connection. +# +# yes = Rewrite/use the source address of the client connection +# no = Forward/use the source address given in the DCC request +# +#dcc_rewrite_source no + # ADVANCED OPTIONS # Options for the advanced user. diff -ur dircproxy-1.0.2.orig/src/cfgfile.c dircproxy-1.0.2/src/cfgfile.c --- dircproxy-1.0.2.orig/src/cfgfile.c Fri Dec 21 21:17:06 2001 +++ dircproxy-1.0.2/src/cfgfile.c Fri Feb 1 16:35:43 2002 @@ -135,6 +135,7 @@ ? x_strdup(DEFAULT_DCC_TUNNEL_INCOMING) : 0); def->dcc_tunnel_outgoing = (DEFAULT_DCC_TUNNEL_OUTGOING ? x_strdup(DEFAULT_DCC_TUNNEL_OUTGOING) : 0); + def->dcc_rewrite_source = DEFAULT_DCC_REWRITE_SOURCE; def->switch_user = (DEFAULT_SWITCH_USER ? x_strdup(DEFAULT_SWITCH_USER) : 0); def->motd_logo = DEFAULT_MOTD_LOGO; def->motd_file = (DEFAULT_MOTD_FILE ? x_strdup(DEFAULT_MOTD_FILE) : 0); @@ -953,6 +954,11 @@ free((class ? class : def)->dcc_tunnel_outgoing); (class ? class : def)->dcc_tunnel_outgoing = str; + + } else if (!strcasecmp(key, "dcc_rewrite_source")) { + /* dcc_rewrite_source yes + dcc_rewrite_source no */ + _cfg_read_bool(&buf, &(class ? class : def)->dcc_rewrite_source); } else if (!strcasecmp(key, "switch_user")) { /* switch_user none diff -ur dircproxy-1.0.2.orig/src/dircproxy.h dircproxy-1.0.2/src/dircproxy.h --- dircproxy-1.0.2.orig/src/dircproxy.h Fri Dec 21 21:15:55 2001 +++ dircproxy-1.0.2/src/dircproxy.h Fri Feb 1 15:59:31 2002 @@ -513,6 +513,13 @@ */ #define DEFAULT_DCC_TUNNEL_OUTGOING 0 +/* DEFAULT_DCC_REWRITE_SOURCE + * Whether to use clients source address instead of the one given in the DCC request + * 1 = Yes + * 0 = No + */ +#define DEFAULT_DCC_REWRITE_SOURCE 0 + /* DEFAULT_SWITCH_USER * Username to create server socket with * 0 = Don't do this diff -ur dircproxy-1.0.2.orig/src/irc_client.c dircproxy-1.0.2/src/irc_client.c --- dircproxy-1.0.2.orig/src/irc_client.c Fri Dec 21 21:15:55 2001 +++ dircproxy-1.0.2/src/irc_client.c Fri Feb 1 17:11:52 2002 @@ -520,7 +520,9 @@ /* Eww, host order, how the hell does this even work between machines of a different byte order? */ if (!t_port) { - r_addr.s_addr = strtoul(cmsg.params[2], (char **)NULL, 10); + r_addr.s_addr = p->conn_class->dcc_rewrite_source + ? ntohl(p->client_addr.sin_addr.s_addr) + : strtoul(cmsg.params[2], (char **)NULL, 10); r_port = atoi(cmsg.params[3]); } else { r_addr.s_addr = INADDR_LOOPBACK; @@ -589,6 +591,41 @@ cmsg.params[0]); } + } else if (!strcmp(cmsg.cmd, "DCC") + && p->conn_class->dcc_rewrite_source) { + if ((cmsg.numparams >= 4) + && (!irc_strcasecmp(cmsg.params[0], "CHAT") + || !irc_strcasecmp(cmsg.params[0], "SEND"))) { + char *tmp, *ptr, *dccmsg; + + /* Strip out this CTCP from the message, replacing it in + a moment with dccmsg */ + tmp = x_sprintf("\001%s\001", unquoted); + ptr = strstr(str, tmp); + dccmsg = 0; + + if (ptr) { + char *oldstr; + + /* Replace IP with the IP of the clients socket */ + dccmsg = x_sprintf("\001DCC %s %s %lu %s\001", + cmsg.params[0], cmsg.params[1], + ntohl(p->client_addr.sin_addr.s_addr), + cmsg.paramstarts[3]); + + /* Cut out the old CTCP and replace with dccmsg */ + *ptr = 0; + ptr += strlen(tmp); + + oldstr = str; + str = x_sprintf("%s%s%s", oldstr, dccmsg, ptr); + + free(oldstr); + free(dccmsg); + } + + free(tmp); + } } else { /* Unknown CTCP */ if (p->conn_class->log_events & IRC_LOG_CTCP) diff -ur dircproxy-1.0.2.orig/src/irc_net.h dircproxy-1.0.2/src/irc_net.h --- dircproxy-1.0.2.orig/src/irc_net.h Fri Dec 21 21:15:55 2001 +++ dircproxy-1.0.2/src/irc_net.h Fri Feb 1 15:58:06 2002 @@ -114,6 +114,8 @@ char *dcc_tunnel_incoming; char *dcc_tunnel_outgoing; + int dcc_rewrite_source; + char *switch_user; int motd_logo;