Пример #1
0
GList *
broadcast_addresses()
{
	GList *result = NULL;
	int s;
	struct lifconf c;
	int count;

	if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
		return (NULL);

	count = number_of_interfaces(s);

	memset(&c, 0, sizeof (c));
	c.lifc_family = AF_INET;
	c.lifc_flags = 0;
	c.lifc_buf = calloc(count, sizeof (struct lifreq));
	c.lifc_len = (count * sizeof (struct lifreq));

	if (ioctl(s, SIOCGLIFCONF, (char *)&c) == 0) {
		struct lifreq *r = c.lifc_req;

		for (count = c.lifc_len / sizeof (struct lifreq);
		     count > 0; count--, r++) {
			char *address = broadcast_address(s, r->lifr_name);

			if (address != NULL) /* add it to the list */
				result = g_list_append(result, address);
		}
	}
	free(c.lifc_buf);
	close(s);

	return (result);
}
Пример #2
0
 bool has_visited_all_interfaces() {
   return interface_index() >= number_of_interfaces();
 }
Пример #3
0
 void set_all_interfaces_visited() {
   _interface_index = number_of_interfaces();
 }