From 8b4dca0af0dccc4223bc1b50a5ae5e55f9414184 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 25 Aug 2005 14:02:29 +0000 Subject: * Show interface names instead of indexes in avahi-discover-standalone GUI git-svn-id: file:///home/lennart/svn/public/avahi/trunk@443 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-discover-standalone/main.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/avahi-discover-standalone/main.c b/avahi-discover-standalone/main.c index 9f70e0d..8c917f8 100644 --- a/avahi-discover-standalone/main.c +++ b/avahi-discover-standalone/main.c @@ -23,7 +23,10 @@ #include #endif +#include #include +#include +#include #include #include @@ -64,6 +67,34 @@ static GHashTable *service_type_hash_table = NULL; static AvahiSServiceResolver *service_resolver = NULL; static struct Service *current_service = NULL; +static const char* getifname(int idx) { + static char t[256]; + static struct ifreq ifreq; + int fd = -1; + + memset(&ifreq, 0, sizeof(ifreq)); + + if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) + if ((fd = socket(PF_INET6, SOCK_DGRAM, 0)) < 0) + goto fail; + + ifreq.ifr_ifindex = idx; + if (ioctl(fd, SIOCGIFNAME, &ifreq) < 0) + goto fail; + + close(fd); + + return ifreq.ifr_name; + + +fail: + if (fd >= 0) + close(fd); + + snprintf(t, sizeof(t), "#%i", idx); + return t; +} + static struct Service *get_service(const gchar *service_type, const gchar *service_name, const gchar*domain_name, AvahiIfIndex interface, AvahiProtocol protocol) { struct ServiceType *st; GList *l; @@ -135,7 +166,7 @@ static void service_browser_callback(AvahiSServiceBrowser *b, AvahiIfIndex inter ppath = gtk_tree_row_reference_get_path(s->service_type->tree_ref); gtk_tree_model_get_iter(GTK_TREE_MODEL(tree_store), &piter, ppath); - snprintf(iface, sizeof(iface), "#%i %s", interface, protocol == AF_INET ? "IPv4" : "IPv6"); + snprintf(iface, sizeof(iface), "%s %s", getifname(interface), protocol == AF_INET ? "IPv4" : "IPv6"); gtk_tree_store_append(tree_store, &iter, &piter); gtk_tree_store_set(tree_store, &iter, 0, s->service_name, 1, iface, 2, s, -1); @@ -204,14 +235,13 @@ static void update_label(struct Service *s, const gchar *hostname, const AvahiAd "Service Type: %s\n" "Service Name: %s\n" "Domain Name: %s\n" - "Interface: %i %s\n" + "Interface: %s %s\n" "Address: %s\n" "TXT Data: %s", s->service_type->service_type, s->service_name, s->domain_name, - s->interface, - s->protocol == AF_INET ? "IPv4" : "IPv6", + getifname(s->interface), s->protocol == AF_INET ? "IPv4" : "IPv6", address, txt_s); -- cgit