]> git.meshlink.io Git - catta/blobdiff - avahi-utils/avahi-dump-all.in
* Show some messages when pygtk or twisted is missing for the execution of the python...
[catta] / avahi-utils / avahi-dump-all.in
index 6e272406b756a420a9b085f984ed28ffd1e1bd4f..c90e964aa9ff65edf4e9c8de41a157b66ce863ad 100755 (executable)
@@ -1,8 +1,31 @@
-#!/usr/bin/env @PYTHON@
+#!@PYTHON@
 # -*-python-*-
 # $Id$ 
 
-import avahi, dbus, gobject, sys
+# This file is part of avahi.
+#
+# avahi is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
+#
+# avahi is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+# License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with avahi; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA.
+
+import sys
+
+try:
+    import avahi, gobject, dbus
+except ImportError:
+    print "Sorry, to use this tool you need to install Avahi, pygtk and python-dbus."
+    sys.exit(1)
 
 try:
     import dbus.glib
@@ -12,8 +35,16 @@ except ImportError, e:
 service_type_browsers = {}
 service_browsers = {}
 
+def siocgifname(interface):
+    global server
+    
+    if interface <= 0:
+        return "any"
+    else:
+        return server.GetNetworkInterfaceNameByIndex(interface)
+
 def service_resolved(interface, protocol, name, type, domain, host, aprotocol, address, port, txt):
-    print "Service data for service '%s' of type '%s' in domain '%s' on %i.%i:" % (name, type, domain, interface, protocol)
+    print "Service data for service '%s' of type '%s' in domain '%s' on %s.%i:" % (name, type, domain, siocgifname(interface), protocol)
     print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, str(txt))
 
 def print_error(err):
@@ -22,13 +53,13 @@ def print_error(err):
 def new_service(interface, protocol, name, type, domain):
     global server
     
-    print "Found service '%s' of type '%s' in domain '%s' on %i.%i." % (name, type, domain, interface, protocol)
+    print "Found service '%s' of type '%s' in domain '%s' on %s.%i." % (name, type, domain, siocgifname(interface), protocol)
 
     # Asynchronous resolving
     server.ResolveService(interface, protocol, name, type, domain, avahi.PROTO_UNSPEC, reply_handler=service_resolved, error_handler=print_error)
 
 def remove_service(interface, protocol, name, type, domain):
-    print "Service '%s' of type '%s' in domain '%s' on %i.%i disappeared." % (name, type, domain, interface, protocol)
+    print "Service '%s' of type '%s' in domain '%s' on %s.%i disappeared." % (name, type, domain, siocgifname(interface), protocol)
  
 def new_service_type(interface, protocol, type, domain):
     global server, service_browsers
@@ -37,7 +68,7 @@ def new_service_type(interface, protocol, type, domain):
     if service_browsers.has_key((interface, protocol, type, domain)):
         return
 
-    print "Browsing for services of type '%s' in domain '%s' on %i.%i ..." % (type, domain, interface, protocol)
+    print "Browsing for services of type '%s' in domain '%s' on %s.%i ..." % (type, domain, siocgifname(interface), protocol)
     
     b = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.ServiceBrowserNew(interface, protocol, type, domain)), avahi.DBUS_INTERFACE_SERVICE_BROWSER)
     b.connect_to_signal('ItemNew', new_service)
@@ -52,7 +83,7 @@ def browse_domain(interface, protocol, domain):
     if service_type_browsers.has_key((interface, protocol, domain)):
         return
 
-    print "Browsing domain '%s' on %i.%i ..." % (domain, interface, protocol)
+    print "Browsing domain '%s' on %s.%i ..." % (domain, siocgifname(interface), protocol)
     
     b = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.ServiceTypeBrowserNew(interface, protocol, domain)), avahi.DBUS_INTERFACE_SERVICE_TYPE_BROWSER)
     b.connect_to_signal('ItemNew', new_service_type)