HostnameThread * hostname6_thread_new (const struct in6_addr *ip6_addr, HostnameThreadCallback callback, gpointer user_data) { HostnameThread *ht; char buf[INET6_ADDRSTRLEN + 1]; ht = g_malloc0 (sizeof (HostnameThread)); g_assert (ht); ht->lock = g_mutex_new (); ht->callback = callback; ht->user_data = user_data; ht->addr6.sin6_family = AF_INET6; ht->addr6.sin6_addr = *ip6_addr; ht->addr = (struct sockaddr *) &ht->addr6; ht->addr_size = sizeof (ht->addr6); ht->thread = g_thread_create (hostname_thread_worker, ht, FALSE, NULL); if (!ht->thread) { hostname_thread_free (ht); return NULL; } if (!inet_ntop (AF_INET, ip6_addr, buf, sizeof (buf))) strcpy (buf, "(unknown)"); nm_log_dbg (LOGD_DNS, "(%p) started IPv6 reverse-lookup thread for address '%s'", ht, buf); return ht; }
static void lookup_callback (HostnameThread *thread, int result, const char *hostname, gpointer user_data) { NMPolicy *policy = (NMPolicy *) user_data; char *msg; /* Update the hostname if the calling lookup thread is the in-progress one */ if (!hostname_thread_is_dead (thread) && (thread == policy->lookup)) { policy->lookup = NULL; if (!hostname) { /* Fall back to localhost.localdomain */ msg = g_strdup_printf ("address lookup failed: %d", result); _set_hostname (policy, TRUE, NULL, msg); g_free (msg); } else _set_hostname (policy, TRUE, hostname, "from address lookup"); } hostname_thread_free (thread); }