From 159c21b75c6efa0952e8d446341b7a037593c350 Mon Sep 17 00:00:00 2001 From: Philipp Homann <3265572+PhilippHomann@users.noreply.github.com> Date: Fri, 4 Feb 2022 10:26:14 +0100 Subject: mpm: Use receiving socket for sending response The receiving socket can be used to send responses. This allows setting firewall rules for USRP detection. --- mpm/python/usrp_mpm/discovery.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'mpm/python/usrp_mpm') diff --git a/mpm/python/usrp_mpm/discovery.py b/mpm/python/usrp_mpm/discovery.py index a9f165ed3..9a216c974 100644 --- a/mpm/python/usrp_mpm/discovery.py +++ b/mpm/python/usrp_mpm/discovery.py @@ -62,8 +62,7 @@ def _discovery_process(state, discovery_addr): # FIXME really, we should only bind to the subnet but I haven't gotten that # working yet sock.bind((("0.0.0.0", MPM_DISCOVERY_PORT))) - send_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - send_sock.setsockopt(socket.IPPROTO_IP, IP_MTU_DISCOVER, IP_PMTUDISC_DO) + sock.setsockopt(socket.IPPROTO_IP, IP_MTU_DISCOVER, IP_PMTUDISC_DO) # TODO yeah I know that's not how you do this discovery_addr_prefix = discovery_addr.replace('.255', '') @@ -83,17 +82,16 @@ def _discovery_process(state, discovery_addr): resp_str = create_response_string(state) send_data = resp_str log.trace("Return data: %s", send_data) - send_sock.sendto(send_data, sender) + sock.sendto(send_data, sender) elif data.strip(b"\0").startswith(b"MPM-ECHO"): log.debug("Received echo request from {sender}" .format(sender=sender[0])) send_data = data try: - send_sock.sendto(send_data, sender) + sock.sendto(send_data, sender) except OSError as ex: log.warning("ECHO send error: %s", str(ex)) except Exception as err: log.error("Unexpected error: `%s' Type: `%s'", str(err), type(err)) sock.close() - send_sock.close() exit(1) -- cgit v1.2.3