# from Twisted
from twisted.internet import defer, threads, reactor
from twisted.internet.protocol import DatagramProtocol
+from twisted.internet.error import CannotListenError
from twisted.python.procutils import which
from twisted.python import log
# avoid this DNS lookup. This also makes node startup fractionally
# faster.
return None
- udpprot = DatagramProtocol()
- port = reactor.listenUDP(0, udpprot)
+
try:
+ udpprot = DatagramProtocol()
+ port = reactor.listenUDP(0, udpprot)
udpprot.transport.connect(target_ipaddr, 7)
localip = udpprot.transport.getHost().host
- except socket.error:
+ d = port.stopListening()
+ d.addErrback(log.err)
+ except (socket.error, CannotListenError):
# no route to that host
localip = None
- d = port.stopListening()
- d.addErrback(log.err)
return localip