cinchrb / cinch

The IRC Bot Building Framework
http://www.rubydoc.info/gems/cinch
MIT License
1k stars 180 forks source link

DCC Address Integer Support #139

Closed Lem closed 11 years ago

Lem commented 11 years ago

I tested to send a file from Irssi to Cinch.

Here the output of the bot

[2013/09/02 21:57:23.943] >> :ABC!~ABC@HOST PRIVMSG cinch :\u0001DCC SEND openwrt_version 1372754541 37061 7\u0001
[2013/09/02 21:57:23.943] II DCC: Incoming DCC SEND: File name: openwrt_version - Size: 7B - IP: 1372754541 - Port: 37061
[2013/09/02 21:57:23.943] !! [New thread] For #<Cinch::Handler @event=:dcc_send pattern=#<Cinch::Pattern:0x00000001b73f80 @prefix=nil, @pattern=//, @suffix=nil>>: #<Thread:0x00000001c53cc0> -- 1 in total.
"1372754541"
[2013/09/02 21:57:23.945] !! /usr/lib64/ruby/1.9.1/ipaddr.rb:544:in `in6_addr': invalid address (ArgumentError)
[2013/09/02 21:57:23.945] !!    /usr/lib64/ruby/1.9.1/ipaddr.rb:481:in `initialize'

using

  def incoming_dcc(m, dcc)
        if dcc.from_private_ip? || dcc.from_localhost?
                puts "IP PRIVATE!!"
        else
                puts "IP NOT PRIVATE!!"
        end
  end

Of course I will get ArgumentError. 1372754541 is not an IP-address :D As descriped in http://irchelp.org/irchelp/rfc/dccspec.html Irssi will use an integer:

void dcc_ip2str(IPADDR *ip, char *host)
{
        IPADDR temp_ip;
        guint32 addr;

        if (*settings_get_str("dcc_own_ip") != '\0') {
                /* overridden IP address */
                net_host2ip(settings_get_str("dcc_own_ip"), &temp_ip);
                ip = &temp_ip;
        }

        if (IPADDR_IS_V6(ip)) {
                /* IPv6 */
                net_ip2host(ip, host);
        } else {
                memcpy(&addr, &ip->ip, sizeof(addr));
                g_snprintf(host, MAX_IP_LEN, "%lu",
                           (unsigned long) htonl(addr));
        }
}

I changed in lib/cinch/dcc/incoming/send.rb the lines

ip   = IPAddr.new(@ip)

to

ip   = IPAddr.new(@ip.to_i, Socket::AF_INET)

and it seems to work with irssi, or at least the exception doesn't appear.

dominikh commented 11 years ago

Please attach the whole stacktrace. process_dcc_send in irc.rb takes care of the integer -> IP translation. By the time it hits any methods in the actual DCC classes, it should be a correct string representation of an IP.

dominikh commented 11 years ago

Ah dammit, never mind. found the bug.

dominikh commented 11 years ago

Closed by e0b5b9a

Lem commented 11 years ago

Thanks for this fast fix :+1: