Use getaddrinfo to create the right socket
This commit is contained in:
parent
1f5cfb2ead
commit
d4302780da
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import re
|
import re
|
||||||
|
import socket
|
||||||
|
|
||||||
from nemubot.channel import Channel
|
from nemubot.channel import Channel
|
||||||
from nemubot.message.printer.IRC import IRC as IRCPrinter
|
from nemubot.message.printer.IRC import IRC as IRCPrinter
|
||||||
@ -240,7 +241,7 @@ class _IRC:
|
|||||||
if self.capabilities is not None:
|
if self.capabilities is not None:
|
||||||
self.write("CAP LS")
|
self.write("CAP LS")
|
||||||
self.write("NICK :" + self.nick)
|
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):
|
def close(self):
|
||||||
|
@ -81,24 +81,17 @@ class _Socket(AbstractServer):
|
|||||||
class _SocketServer(_Socket):
|
class _SocketServer(_Socket):
|
||||||
|
|
||||||
def __init__(self, host, port, bind=None, **kwargs):
|
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)
|
super().__init__(family=family, type=type, proto=proto, **kwargs)
|
||||||
assert(isinstance(port, int))
|
|
||||||
|
|
||||||
self._host = host
|
self._sockaddr = sockaddr
|
||||||
self._port = port
|
|
||||||
self._bind = bind
|
self._bind = bind
|
||||||
|
|
||||||
|
|
||||||
@property
|
|
||||||
def host(self):
|
|
||||||
return self._host
|
|
||||||
|
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
self.logger.info("Connection to %s:%d", self._host, self._port)
|
self.logger.info("Connection to %s:%d", *self._sockaddr[:2])
|
||||||
super().connect((self._host, self._port))
|
super().connect(self._sockaddr)
|
||||||
|
|
||||||
if self._bind:
|
if self._bind:
|
||||||
super().bind(self._bind)
|
super().bind(self._bind)
|
||||||
|
Loading…
Reference in New Issue
Block a user