+ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ gchar txt[256];
+ g_snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
+ return respond_error(c, m, AVAHI_ERR_OS, txt);
+ }
+
+ memset(&ifr, 0, sizeof(ifr));
+ ifr.ifr_ifindex = idx;
+
+ if (ioctl(fd, SIOCGIFNAME, &ifr) < 0) {
+ gchar txt[256];
+ g_snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
+ close(fd);
+ return respond_error(c, m, AVAHI_ERR_OS, txt);
+ }
+
+ close(fd);
+
+ return respond_string(c, m, ifr.ifr_name);
+#endif
+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetNetworkInterfaceIndexByName")) {
+ gchar *n;
+ int fd;
+ struct ifreq ifr;
+
+ if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n) {
+ avahi_log_warn("Error parsing Server::GetNetworkInterfaceIndexByName message");
+ goto fail;
+ }
+
+#ifdef VALGRIND_WORKAROUND
+ return respond_int32(c, m, 1);
+#else
+ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ gchar txt[256];
+ g_snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
+ return respond_error(c, m, AVAHI_ERR_OS, txt);
+ }
+
+ memset(&ifr, 0, sizeof(ifr));
+ g_snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", n);
+
+ if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) {
+ gchar txt[256];
+ g_snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
+ close(fd);
+ return respond_error(c, m, AVAHI_ERR_OS, txt);
+ }
+
+ close(fd);
+
+ return respond_int32(c, m, ifr.ifr_ifindex);
+#endif