client-test \
srv-test \
xdg-config-test \
- rr-test
+ rr-test \
+ check-nss-test
endif
resolver.c \
publish.h lookup.h \
xdg-config.c xdg-config.h \
+ check-nss.c \
../avahi-common/dbus.c ../avahi-common/dbus.h \
../avahi-common/dbus-watch-glue.c ../avahi-common/dbus-watch-glue.h
xdg_config_test_CFLAGS = $(AM_CFLAGS)
xdg_config_test_LDADD = $(AM_LDADD)
+check_nss_test_SOURCES = check-nss.c check-nss-test.c client.h
+check_nss_test_CFLAGS = $(AM_CFLAGS)
+check_nss_test_LDADD = $(AM_LDADD)
+
+if HAVE_DLOPEN
+check_nss_test_LDADD += -ldl
+libavahi_client_la_LIBADD += -ldl
+endif
+
endif
--- /dev/null
+/* $Id$ */
+
+/***
+ 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.1 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 Lesser 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.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+
+#include <avahi-client/client.h>
+
+int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
+ printf("NSS Support available: %s\n", avahi_nss_support() ? "yes" : "no");
+}
--- /dev/null
+/* $Id$ */
+
+/***
+ 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.1 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 Lesser 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.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_DLOPEN
+#include <dlfcn.h>
+#endif
+#include <stdlib.h>
+
+#include "client.h"
+
+int avahi_nss_support(void) {
+ int b = 0;
+
+#ifdef HAVE_DLOPEN
+ static const char * const libs[] = {
+ "libnss_mdns.so.2",
+ "libnss_mdns4.so.2",
+ "libnss_mdns6.so.2",
+ NULL };
+
+ const char * const *l;
+
+ for (l = libs; *l; l++) {
+ void *dl;
+
+ if ((dl = dlopen(*l, RTLD_LAZY))) {
+ b = 1;
+ dlclose(dl);
+ break;
+ }
+ }
+#endif
+
+ return b;
+}
/** Return the local service cookie. returns AVAHI_SERVICE_COOKIE_INVALID on failure. */
uint32_t avahi_client_get_local_service_cookie(AvahiClient *client);
+/** Return 1 if gethostbyname() supports mDNS lookups, 0 otherwise */
+int avahi_nss_support(void);
+
AVAHI_C_DECL_END
#endif
dbus-sync-host-name-resolver.c \
dbus-sync-service-resolver.c \
dbus-record-browser.c \
- ../avahi-common/dbus.c ../avahi-common/dbus.h \
- ../avahi-common/dbus-watch-glue.c ../avahi-common/dbus-watch-glue.h
+ ../avahi-common/dbus.c ../avahi-common/dbus.h \
+ ../avahi-common/dbus-watch-glue.c ../avahi-common/dbus-watch-glue.h \
+ ../avahi-client/check-nss.c
avahi_daemon_LDADD += \
$(DBUS_LIBS)
+if HAVE_DLOPEN
+avahi_daemon_LDADD += -ldl
+endif
+
avahi_daemon_CFLAGS += $(DBUS_CFLAGS)
dbusservice_DATA = avahi-dbus.conf
<arg name="name" type="s" direction="out"/>
</method>
+ <method name="IsNSSSupportAvailable">
+ <arg name="yes" type="b" direction="out"/>
+ </method>
+
<method name="GetState">
<arg name="state" type="i" direction="out"/>
</method>
return avahi_dbus_respond_string(c, m, avahi_server_get_host_name_fqdn(avahi_server));
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "IsNSSSupportAvailable")) {
+ if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INVALID))) {
+ avahi_log_warn("Error parsing Server::IsNSSSupportAvailable message");
+ goto fail;
+ }
+
+ return avahi_dbus_respond_boolean(c, m, nss_support);
+
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetVersionString")) {
if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INVALID))) {
AvahiServer *avahi_server = NULL;
AvahiSimplePoll *simple_poll_api = NULL;
static char *argv0 = NULL;
+int nss_support = 0;
typedef enum {
DAEMON_RUN,
}
}
+/* Imported from ../avahi-client/nss-check.c */
+int avahi_nss_support(void);
static int run_server(DaemonConfig *c) {
int r = -1;
assert(c);
+ if (!(nss_support = avahi_nss_support()))
+ avahi_log_warn("WARNING: No NSS support for mDNS detected, consider installing nss-mdns!");
+
if (!(simple_poll_api = avahi_simple_poll_new())) {
avahi_log_error("Failed to create main loop object.");
goto finish;
extern AvahiServer *avahi_server;
extern AvahiSimplePoll *simple_poll_api;
+extern int nss_support;
+
#endif
port = 8080
address = "127.0.0.1"
-use_host_names = False
+use_host_names = None
domain = "local"
class AvahiBookmarks(resource.Resource):
services = {}
- def __init__(self):
+ def __init__(self, use_host_names):
resource.Resource.__init__(self)
self.bus = dbus.SystemBus()
self.browse_service_type("_https._tcp")
self.browse_service_type("_ftp._tcp")
+ if use_host_names is None:
+ try:
+ self.use_host_names = self.server.IsNSSSupportAvailable()
+ except:
+ self.use_host_names = False
+ else:
+ self.use_host_names = use_host_names
+
def browse_service_type(self, stype):
global domain
t += '<hr noshade/><p style="font-size: 8; font-family: sans-serif">Served by %s</p></body></html>' % self.version_string
- return t
+ return str(t)
def new_service(self, interface, protocol, name, type, domain, flags):
interface, protocol, name, type, domain, host, aprotocol, address, port, txt, flags = self.server.ResolveService(interface, protocol, name, type, domain, avahi.PROTO_UNSPEC, dbus.UInt32(0))
- if use_host_names:
+ if self.use_host_names:
h = host
else:
if aprotocol == avahi.PROTO_INET6:
print " -h --help Show this help"
print " -p --port PORT Specify the port to use (default %u)" % port
print " -a --address ADDRESS Specify the address to bind to (default %s)" % address
- print " -H --host-names Show all services, regardless of the type"
+ print " -H --host-names Show links with real hostnames"
+ print " -A --addresses Show links with numeric IP addresses"
print " -d --domain DOMAIN Specify the domain to browse"
sys.exit(retval)
try:
- opts, args = getopt.getopt(sys.argv[1:], "hp:a:Hd:", ["help", "port=", "address=", "host-names", "domain="])
+ opts, args = getopt.getopt(sys.argv[1:], "hp:a:HAd:", ["help", "port=", "address=", "host-names", "addresses", "domain="])
except getopt.GetoptError:
usage(2)
if o in ("-H", "--host-names"):
use_host_names = True
+ if o in ("-A", "--addresses"):
+ use_host_names = False
+
if o in ("-d", "--domain"):
domain = a
-
-site = server.Site(AvahiBookmarks())
+
+site = server.Site(AvahiBookmarks(use_host_names))
reactor.listenTCP(port, site, interface=address)
print "Now point your web browser to http://%s:%u/!" % (address, port)
AC_DEFINE([ENABLE_CHROOT], 1, [Enable chroot() usage])
fi
+AC_CHECK_LIB(dl, dlopen, [ AC_CHECK_HEADERS(dlfcn.h, HAVE_DLOPEN=yes, HAVE_DLOPEN=no) ], HAVE_DLOPEN=no)
+if test "x$HAVE_DLOPEN" = "xyes" ; then
+ AC_DEFINE([HAVE_DLOPEN],1,[Have dlopen()])
+fi
+AM_CONDITIONAL(HAVE_DLOPEN, test "x$HAVE_DLOPEN" = "xyes")
+
# Check for pkg-config manually first, as if its not installed the
# PKG_PROG_PKG_CONFIG macro won't be defined.
AC_CHECK_PROG(have_pkg_config, pkg-config, yes, no)