Use getaddrinfo to create the right socket

This commit is contained in:
nemunaire 2016-08-10 23:56:50 +02:00
parent 1f5cfb2ead
commit d4302780da
2 changed files with 7 additions and 13 deletions

View File

@ -16,6 +16,7 @@
from datetime import datetime
import re
import socket
from nemubot.channel import Channel
from nemubot.message.printer.IRC import IRC as IRCPrinter
@ -240,7 +241,7 @@ class _IRC:
if self.capabilities is not None:
self.write("CAP LS")
self.write("NICK :" + self.nick)
self.write("USER %s %s bla :%s" % (self.username, self.host, self.realname))
self.write("USER %s %s bla :%s" % (self.username, socket.getfqdn(), self.realname))
def close(self):

View File

@ -81,24 +81,17 @@ class _Socket(AbstractServer):
class _SocketServer(_Socket):
def __init__(self, host, port, bind=None, **kwargs):
super().__init__(family=socket.AF_INET, **kwargs)
(family, type, proto, canonname, sockaddr) = socket.getaddrinfo(host, port)[0]
assert(host is not None)
assert(isinstance(port, int))
super().__init__(family=family, type=type, proto=proto, **kwargs)
self._host = host
self._port = port
self._sockaddr = sockaddr
self._bind = bind
@property
def host(self):
return self._host
def connect(self):
self.logger.info("Connection to %s:%d", self._host, self._port)
super().connect((self._host, self._port))
self.logger.info("Connection to %s:%d", *self._sockaddr[:2])
super().connect(self._sockaddr)
if self._bind:
super().bind(self._bind)