Add handling of opening sockets to communicate with IPV6 hosts.

This commit is contained in:
James Vega 2004-06-20 07:37:25 +00:00
parent 17a40423ee
commit 9d9c3020ca
3 changed files with 34 additions and 6 deletions

View File

@ -59,9 +59,16 @@ class DCC(callbacks.Privmsg):
text = privmsgs.getArgs(args)
def openChatPort():
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(60)
host = ircutils.hostFromHostmask(irc.prefix)
try:
inet = utils.getSocket(host)
except socket.error, e:
s = 'Error connecting to %s: %s'
self.log.warning(s, host, e)
irc.replyError()
return
sock = socket.socket(inet, socket.SOCK_STREAM)
sock.settimeout(60)
if conf.supybot.externalIP():
ip = conf.supybot.externalIP()
else:

View File

@ -139,7 +139,13 @@ class SocketDriver(drivers.IrcDriver):
self._scheduleReconnect()
return
self.irc.reset()
self.conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
inet = utils.getSocket(self.server[0])
except socket.error, e:
log.warning('Error connecting to %s: %s', self.server[0], e)
self.reconnect(wait=True)
return
self.conn = socket.socket(inet, socket.SOCK_STREAM)
# We allow more time for the connect here, since it might take longer.
# At least 10 seconds.
self.conn.settimeout(max(10, conf.supybot.drivers.poll()*10))

View File

@ -555,6 +555,21 @@ def changeFunctionName(f, name, doc=None):
newf.__doc__ = doc
return newf
def getSocket(host):
"""Returns a socket of the correct AF_INET type (v4 or v6) in order to
communicate with host.
"""
try:
host = socket.gethostbyname(host)
except socket.error:
raise
if isIP(host):
return socket.socket(socket.INET, socket.SOCK_STREAM)
elif isIPV6(host):
return socket.socket(socket.INET6, socket.SOCK_STREAM)
else:
raise socket.error, 'Something wonky happened.'
_ipchars = string.digits + '.'
def isIP(s):
"""Returns whether or not a given string is an IPV4 address.