[avahi] how to determine if an AvahiAddress is the local machine's?
Charles Schmidt
cschmidt2 at emich.edu
Fri Sep 9 00:16:48 PDT 2005
-
As far as I can tell, there is no API for determining if a given
AvahiAddress refers to an IP that the local machine has. Something like
avahi_address_is_localhost() or avahi_address_is_this_host() would be
quite nice for filtering through resolve responses to get only those
that aren't services from the local machine.
Right now, I'm using:
static gboolean
is_local_address (const gchar *address)
{
/* address here was got with avahi_address_snprint() */
static struct hostent *he = NULL;
struct in_addr addr;
gint i;
gint ret;
gchar hostname[255 + 6];
ret = gethostname (hostname, 255);
if (ret) {
return FALSE;
}
strncat (hostname, ".local", 6);
he = gethostbyname (hostname);
if (he == NULL) {
return FALSE;
}
for (i = 0; he->h_addr_list[i]; i++) {
memcpy (&addr, he->h_addr_list[0], sizeof (struct in_addr));
if (strcmp (inet_ntoa (addr), address) == 0) {
return TRUE;
}
}
return FALSE;
}
But I'm not sure that this is a) the best way or b) something that will
work in all situations (multiple interfaces). Can anyone suggest a
better way to do this?
-charlie
More information about the avahi
mailing list