""" TCP server that communicates with terminals """
from logging import getLogger
-from socket import socket, AF_INET, SOCK_STREAM, SOL_SOCKET, SO_REUSEADDR
+from socket import socket, AF_INET6, SOCK_STREAM, SOL_SOCKET, SO_REUSEADDR
from time import time
from struct import pack
import zmq
zpub.bind(conf.get("collector", "publishurl"))
zsub = zctx.socket(zmq.SUB)
zsub.connect(conf.get("collector", "listenurl"))
- tcpl = socket(AF_INET, SOCK_STREAM)
+ tcpl = socket(AF_INET6, SOCK_STREAM)
tcpl.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
tcpl.bind(("", conf.getint("collector", "port")))
tcpl.listen(5)
__all__ = "Bcast", "Resp"
def pack_peer(peeraddr):
- saddr, port = peeraddr
- addr = ip.ip_address(saddr)
+ saddr, port, _x, _y = peeraddr
+ addr6 = ip.ip_address(saddr)
+ addr = addr6.ipv4_mapped
+ if addr is None:
+ addr = addr6
return pack("B", addr.version) + (addr.packed + b"\0\0\0\0\0\0\0\0\0\0\0\0")[:16] + pack("!H", port)
def unpack_peer(buffer):