- struct PendingMessage *p;
- struct ClientStartMessage *init;
-
- GNUNET_assert (NULL == sh->client);
- sh->client = GNUNET_CLIENT_connect ("ats", sh->cfg);
- GNUNET_assert (NULL != sh->client);
- if ((NULL == (p = sh->pending_head)) || (GNUNET_YES != p->is_init))
- {
- p = GNUNET_malloc (sizeof (struct PendingMessage) +
- sizeof (struct ClientStartMessage));
- p->size = sizeof (struct ClientStartMessage);
- p->is_init = GNUNET_YES;
- init = (struct ClientStartMessage *) &p[1];
- init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START);
- init->header.size = htons (sizeof (struct ClientStartMessage));
- init->start_flag = htonl (START_FLAG_SCHEDULING);
- GNUNET_CONTAINER_DLL_insert (sh->pending_head, sh->pending_tail, p);
- }
- do_transmit (sh);
-}
-
-
-/**
- * delete the current network list
- */
-static void
-delete_networks (struct GNUNET_ATS_SchedulingHandle *sh)
-{
- struct ATS_Network * cur = sh->net_head;
- while (cur != NULL)
- {
- GNUNET_CONTAINER_DLL_remove(sh->net_head, sh->net_tail, cur);
- GNUNET_free (cur);
- cur = sh->net_head;
- }
-}
-
-
-static int
-interface_proc (void *cls, const char *name,
- int isDefault,
- const struct sockaddr *
- addr,
- const struct sockaddr *
- broadcast_addr,
- const struct sockaddr *
- netmask, socklen_t addrlen)
-{
- struct GNUNET_ATS_SchedulingHandle * sh = cls;
- /* Calculate network */
- struct ATS_Network *net = NULL;
-
- /* Skipping IPv4 loopback addresses since we have special check */
- if (addr->sa_family == AF_INET)
- {
- struct sockaddr_in * a4 = (struct sockaddr_in *) addr;
-
- if ((a4->sin_addr.s_addr & htonl(0xff000000)) == htonl (0x7f000000))
- return GNUNET_OK;
- }
- /* Skipping IPv6 loopback addresses since we have special check */
- if (addr->sa_family == AF_INET6)
- {
- struct sockaddr_in6 * a6 = (struct sockaddr_in6 *) addr;
- if (IN6_IS_ADDR_LOOPBACK (&a6->sin6_addr))
- return GNUNET_OK;
- }
-
- if (addr->sa_family == AF_INET)
- {
- struct sockaddr_in *addr4 = (struct sockaddr_in *) addr;
- struct sockaddr_in *netmask4 = (struct sockaddr_in *) netmask;
- struct sockaddr_in *tmp = NULL;
- struct sockaddr_in network4;
-
- net = GNUNET_malloc(sizeof (struct ATS_Network) + 2 * sizeof (struct sockaddr_in));
- tmp = (struct sockaddr_in *) &net[1];
- net->network = (struct sockaddr *) &tmp[0];
- net->netmask = (struct sockaddr *) &tmp[1];
- net->length = addrlen;
-
- memset (&network4, 0, sizeof (network4));
- network4.sin_family = AF_INET;
-#if HAVE_SOCKADDR_IN_SIN_LEN
- network4.sin_len = sizeof (network4);
-#endif
- network4.sin_addr.s_addr = (addr4->sin_addr.s_addr & netmask4->sin_addr.s_addr);
-
- memcpy (net->netmask, netmask4, sizeof (struct sockaddr_in));
- memcpy (net->network, &network4, sizeof (struct sockaddr_in));
- }
-
- if (addr->sa_family == AF_INET6)
- {
- struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *) addr;
- struct sockaddr_in6 *netmask6 = (struct sockaddr_in6 *) netmask;
- struct sockaddr_in6 * tmp = NULL;
- struct sockaddr_in6 network6;
-
- net = GNUNET_malloc(sizeof (struct ATS_Network) + 2 * sizeof (struct sockaddr_in6));
- tmp = (struct sockaddr_in6 *) &net[1];
- net->network = (struct sockaddr *) &tmp[0];
- net->netmask = (struct sockaddr *) &tmp[1];
- net->length = addrlen;
-
- memset (&network6, 0, sizeof (network6));
- network6.sin6_family = AF_INET6;
-#if HAVE_SOCKADDR_IN_SIN_LEN
- network6.sin6_len = sizeof (network6);
-#endif
- int c = 0;
- uint32_t *addr_elem = (uint32_t *) &addr6->sin6_addr;
- uint32_t *mask_elem = (uint32_t *) &netmask6->sin6_addr;
- uint32_t *net_elem = (uint32_t *) &network6.sin6_addr;
- for (c = 0; c < 4; c++)
- net_elem[c] = addr_elem[c] & mask_elem[c];
-
- memcpy (net->netmask, netmask6, sizeof (struct sockaddr_in6));
- memcpy (net->network, &network6, sizeof (struct sockaddr_in6));
- }