Avoid starting Zeroconf if ip unspecified or set to localhost. Pick one interface address when given IP is 0.0.0.0
authorEdouard Tisserant
Mon, 28 Nov 2011 13:46:48 +0100
changeset 648 73295e742da2
parent 647 edce87412f5a
child 649 c48023b6f0ec
Avoid starting Zeroconf if ip unspecified or set to localhost. Pick one interface address when given IP is 0.0.0.0
Beremiz_service.py
runtime/ServicePublisher.py
targets/LPC/__init__.py
--- a/Beremiz_service.py	Tue Nov 22 02:07:00 2011 +0100
+++ b/Beremiz_service.py	Mon Nov 28 13:46:48 2011 +0100
@@ -471,7 +471,10 @@
         
         # Configure and publish service
         # Not publish service if localhost in address params
-        if self.servicename is not None and self.ip_addr != "localhost" and self.ip_addr != "127.0.0.1":    
+        if (self.servicename is not None and 
+            self.ip_addr is not None and 
+            self.ip_addr != "localhost" and 
+            self.ip_addr != "127.0.0.1"):
             print "Publishing service on local network"
             self.servicepublisher = ServicePublisher.ServicePublisher()
             self.servicepublisher.RegisterService(self.servicename, self.ip_addr, self.port)
--- a/runtime/ServicePublisher.py	Tue Nov 22 02:07:00 2011 +0100
+++ b/runtime/ServicePublisher.py	Mon Nov 28 13:46:48 2011 +0100
@@ -50,13 +50,13 @@
         self.service_name = 'Beremiz_%s.%s'%(name,self.service_type)
         self.name = name
         self.port = port
-        # No ip params -> get host ip
-        if ip is None:
-            ip = self.gethostaddr()
 
         self.server = Zeroconf.Zeroconf(ip)
+        print "MDNS brodcasting on :"+ip
 
-        # address: IP address as unsigned short, network byte order
+        if ip == "0.0.0.0":
+            ip = self.gethostaddr()
+        print "MDNS brodcasted service address :"+ip
         self.ip_32b = socket.inet_aton(ip)
 
         self.server.registerService(
@@ -65,7 +65,6 @@
                                   self.ip_32b,
                                   self.port,
                                   properties = self.serviceproperties))
-        print "MDNS brodcasting on :"+ip
         self.retrytimer=None
     
     def UnRegisterService(self):
--- a/targets/LPC/__init__.py	Tue Nov 22 02:07:00 2011 +0100
+++ b/targets/LPC/__init__.py	Mon Nov 28 13:46:48 2011 +0100
@@ -1,6 +1,6 @@
 import os
 from subprocess import Popen,PIPE
-from .. import toolchain_makefile
+from ..toolchain_makefile import toolchain_makefile
 import hashlib
 
 class LPC_target(toolchain_makefile):