#include <assert.h>
#include <string.h>
#include <net/if.h>
+#include <locale.h>
#include <avahi-common/simple-watch.h>
#include <avahi-common/error.h>
#include "sigint.h"
+#ifdef HAVE_GDBM
+#include "stdb.h"
+#endif
+
typedef enum {
COMMAND_HELP,
COMMAND_VERSION,
int show_all;
Command command;
int resolve;
+#ifdef HAVE_GDBM
+ int no_db_lookup;
+#endif
} Config;
-
typedef struct ServiceInfo ServiceInfo;
struct ServiceInfo {
return NULL;
}
+static void print_service_line(Config *config, char c, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain) {
+ char ifname[IF_NAMESIZE];
+
+#ifdef HAVE_GDBM
+ if (!config->no_db_lookup)
+ type = stdb_lookup(type);
+#endif
+
+ printf("%c %4s %4s %-*s %-20s %s\n",
+ c,
+ if_indextoname(interface, ifname), avahi_proto_to_string(protocol),
+ n_columns-35, name, type, domain);
+}
+
static void service_resolver_callback(
AvahiServiceResolver *r,
AvahiIfIndex interface,
switch (event) {
case AVAHI_RESOLVER_FOUND: {
char address[AVAHI_ADDRESS_STR_MAX], *t;
- char ifname[IF_NAMESIZE];
avahi_address_snprint(address, sizeof(address), a);
t = avahi_string_list_to_string(txt);
- printf("= %4s %4s %-*s %-20s %s\n"
- " hostname = [%s]\n"
+ print_service_line(i->config, '=', interface, protocol, name, type, domain);
+
+ printf(" hostname = [%s]\n"
" address = [%s]\n"
" port = [%i]\n"
" txt = [%s]\n",
- if_indextoname(interface, ifname), avahi_proto_to_string(protocol),
- n_columns-35, name, type, domain,
host_name,
address,
port,
switch (event) {
case AVAHI_BROWSER_NEW: {
- char ifname[IF_NAMESIZE];
if (c->ignore_local && (flags & AVAHI_LOOKUP_RESULT_LOCAL))
break;
add_service(c, interface, protocol, name, type, domain);
- printf("+ %4s %4s %-*s %-20s %s\n", if_indextoname(interface, ifname), avahi_proto_to_string(protocol), n_columns-35, name, type, domain);
+ print_service_line(c, '+', interface, protocol, name, type, domain);
break;
}
case AVAHI_BROWSER_REMOVE: {
- char ifname[IF_NAMESIZE];
ServiceInfo *info;
if (!(info = find_service(interface, protocol, name, type, domain)))
remove_service(c, info);
- printf("- %4s %4s %-*s %-20s %s\n", if_indextoname(interface, ifname), avahi_proto_to_string(protocol), n_columns-35, name, type, domain);
+ print_service_line(c, '-', interface, protocol, name, type, domain);
break;
}
" -t --terminate Terminate after getting or more or less complete list\n"
" -c --cache Terminate after dumping all entries from the cache\n"
" -l --ignore-local Ignore local services\n"
- " -r --resolve Resolve services found\n",
- argv0, argv0);
-}
+ " -r --resolve Resolve services found\n"
+#ifdef HAVE_GDBM
+ " -k --no-db-lookup Don't lookup service types\n"
+#endif
+ , argv0, argv0);
+}
static int parse_command_line(Config *c, int argc, char *argv[]) {
int o;
{ "cache", no_argument, NULL, 'c' },
{ "ignore-local", no_argument, NULL, 'l' },
{ "resolve", no_argument, NULL, 'r' },
+#ifdef HAVE_GDBM
+ { "no-db-lookup", no_argument, NULL, 'k' },
+#endif
{ NULL, 0, NULL, 0 }
};
c->ignore_local =
c->resolve = 0;
c->domain = c->stype = NULL;
+
+#ifdef HAVE_GDBM
+ c->no_db_lookup = 0;
+#endif
opterr = 0;
- while ((o = getopt_long(argc, argv, "hVd:avtclr", long_options, NULL)) >= 0) {
+ while ((o = getopt_long(argc, argv, "hVd:avtclr"
+#ifdef HAVE_GDBM
+ "k"
+#endif
+ , long_options, NULL)) >= 0) {
switch(o) {
case 'h':
case 'r':
c->resolve = 1;
break;
+#ifdef HAVE_GDBM
+ case 'k':
+ c->no_db_lookup = 1;
+ break;
+#endif
default:
fprintf(stderr, "Invalid command line argument: %c\n", o);
return -1;
const char *argv0;
char *ec;
+ setlocale(LC_ALL, "");
+
if ((argv0 = strrchr(argv[0], '/')))
argv0++;
else
avahi_string_list_free(browsed_types);
+#ifdef HAVE_GDBM
+ stdb_shutdown();
+#endif
+
return ret;
}