Use getaddrinfo to create the right socket
This commit is contained in:
parent
1f5cfb2ead
commit
d4302780da
@ -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):
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user