summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2013-11-02 10:56:53 +0100
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2013-11-02 11:30:39 +0100
commitfbe8eeb73cf5f5d1f819ea6c0350e67014b4a26b (patch)
treeb0d133c1e6dcca3ea6d0486883d116a14622c1c2
parentdabad2ae7fd015cb4c63f0e658cac17bd479c081 (diff)
Solve Socket vs URI IPv6 handling in Ruby
-rw-r--r--lib/rbot/ircsocket.rb16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/rbot/ircsocket.rb b/lib/rbot/ircsocket.rb
index 4c11094b..029d1ca5 100644
--- a/lib/rbot/ircsocket.rb
+++ b/lib/rbot/ircsocket.rb
@@ -303,20 +303,30 @@ module Irc
@conn_count += 1
@server_uri = URI.parse(srv_uri)
@server_uri.port = 6667 if !@server_uri.port
+
debug "connection attempt \##{@conn_count} (#{@server_uri.host}:#{@server_uri.port})"
+ # if the host is a bracketed (IPv6) address, strip the brackets
+ # since Ruby doesn't like them in the Socket host parameter
+ # FIXME it would be safer to have it check for a valid
+ # IPv6 bracketed address rather than just stripping the brackets
+ srv_host = @server_uri.host
+ if srv_host.match(/\A\[(.*)\]\z/)
+ srv_host = $1
+ end
+
if(@host)
begin
- sock=TCPSocket.new(@server_uri.host, @server_uri.port, @host)
+ sock=TCPSocket.new(srv_host, @server_uri.port, @host)
rescue ArgumentError => e
error "Your version of ruby does not support binding to a "
error "specific local address, please upgrade if you wish "
error "to use HOST = foo"
error "(this option has been disabled in order to continue)"
- sock=TCPSocket.new(@server_uri.host, @server_uri.port)
+ sock=TCPSocket.new(srv_host, @server_uri.port)
end
else
- sock=TCPSocket.new(@server_uri.host, @server_uri.port)
+ sock=TCPSocket.new(srv_host, @server_uri.port)
end
if(@ssl)
require 'openssl'