Skip to content

Commit

Permalink
fix(service): register Zeroconf service for all non-loopback addresses
Browse files Browse the repository at this point in the history
Signed-off-by: Cedric Hombourger <[email protected]>
  • Loading branch information
chombourger committed Dec 31, 2024
1 parent 0f6aad0 commit 5b348b3
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions mtda-service
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import argparse
import daemon
import lockfile
import netifaces
import os
import os.path
import signal
Expand Down Expand Up @@ -56,12 +57,16 @@ class Application:
status = self.server()
return status

def _ip(self):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('192.0.2.0', 0))
ip = s.getsockname()[0]
s.close()
return ip
def _addresses(self):
results = []
for iface in netifaces.interfaces():
if iface.startswith("lo"):
continue
if netifaces.AF_INET in netifaces.ifaddresses(iface):
addresses = netifaces.ifaddresses(iface)[netifaces.AF_INET]
for addr in addresses:
results.append(addr['addr'])
return results

def server(self):
# Start our agent
Expand All @@ -82,10 +87,11 @@ class Application:
}
deviceType = CONSTS.MDNS.TYPE
name = self.agent.name
addresses = self._addresses()
info = zeroconf.ServiceInfo(
type_=deviceType,
name=f'{name}.{deviceType}',
addresses=[socket.inet_aton(self._ip())],
addresses=[socket.inet_aton(addr) for addr in addresses],
port=int(self.agent.ctrlport),
properties=props,
server=f'{name}.local.')
Expand Down

0 comments on commit 5b348b3

Please sign in to comment.