32#define INTERFACE_PROCESSING_INTERVAL GNUNET_TIME_relative_multiply ( \
33 GNUNET_TIME_UNIT_MINUTES, 2)
132 while (NULL != (cur =
is->net_head))
160 const struct sockaddr *addr,
161 const struct sockaddr *broadcast_addr,
162 const struct sockaddr *
netmask,
171 (void) broadcast_addr;
174 if (addr->sa_family == AF_INET)
176 const struct sockaddr_in *a4 = (
const struct sockaddr_in *) addr;
178 if ((a4->sin_addr.s_addr & htonl (0xff000000)) == htonl (0x7f000000))
182 if (addr->sa_family == AF_INET6)
184 const struct sockaddr_in6 *a6 = (
const struct sockaddr_in6 *) addr;
185 if (IN6_IS_ADDR_LOOPBACK (&a6->sin6_addr))
189 if (addr->sa_family == AF_INET)
191 const struct sockaddr_in *addr4 = (
const struct sockaddr_in *) addr;
192 const struct sockaddr_in *netmask4 = (
const struct sockaddr_in *) netmask;
193 struct sockaddr_in *tmp;
194 struct sockaddr_in network4;
198 tmp = (
struct sockaddr_in *) &net[1];
199 net->network = (
struct sockaddr *) &tmp[0];
200 net->netmask = (
struct sockaddr *) &tmp[1];
201 net->length = addrlen;
206 network4.sin_family = AF_INET;
207#if HAVE_SOCKADDR_IN_SIN_LEN
208 network4.sin_len =
sizeof(network4);
210 network4.sin_addr.s_addr = (addr4->sin_addr.s_addr
211 & netmask4->sin_addr.s_addr);
215 sizeof(
struct sockaddr_in));
218 sizeof(
struct sockaddr_in));
221 if (addr->sa_family == AF_INET6)
223 const struct sockaddr_in6 *addr6 = (
const struct sockaddr_in6 *) addr;
224 const struct sockaddr_in6 *netmask6 = (
const struct sockaddr_in6 *) netmask;
225 struct sockaddr_in6 *tmp;
226 struct sockaddr_in6 network6;
230 tmp = (
struct sockaddr_in6 *) &net[1];
231 net->network = (
struct sockaddr *) &tmp[0];
232 net->netmask = (
struct sockaddr *) &tmp[1];
233 net->length = addrlen;
235 memset (&network6, 0,
sizeof(network6));
236 network6.sin6_family = AF_INET6;
237#if HAVE_SOCKADDR_IN_SIN_LEN
238 network6.sin6_len =
sizeof(network6);
242 uint32_t *addr_elem = (uint32_t *) &addr6->sin6_addr;
243 uint32_t *mask_elem = (uint32_t *) &netmask6->sin6_addr;
244 uint32_t *net_elem = (uint32_t *) &network6.sin6_addr;
245 for (c = 0; c < 4; c++)
246 net_elem[c] = addr_elem[c] & mask_elem[c];
250 sizeof(
struct sockaddr_in6));
253 sizeof(
struct sockaddr_in6));
265 "Adding network `%s', netmask `%s'\n",
289 is->interface_task = NULL;
310 const struct sockaddr *addr,
316 switch (addr->sa_family)
324 const struct sockaddr_in *a4 = (
const struct sockaddr_in *) addr;
326 if ((a4->sin_addr.s_addr & htonl (0xff000000)) == htonl (0x7f000000))
333 const struct sockaddr_in6 *a6 = (
const struct sockaddr_in6 *) addr;
335 if (IN6_IS_ADDR_LOOPBACK (&a6->sin6_addr))
348 if (addrlen != cur->
length)
353 if (addr->sa_family == AF_INET)
355 const struct sockaddr_in *a4 = (
const struct sockaddr_in *) addr;
356 const struct sockaddr_in *net4 = (
const struct
358 const struct sockaddr_in *mask4 = (
const struct
361 if (((a4->sin_addr.s_addr & mask4->sin_addr.s_addr)) ==
362 net4->sin_addr.s_addr)
365 if (addr->sa_family == AF_INET6)
367 const struct sockaddr_in6 *a6 = (
const struct sockaddr_in6 *) addr;
368 const struct sockaddr_in6 *net6 = (
const struct
370 const struct sockaddr_in6 *mask6 = (
const struct
375 uint32_t *addr_elem = (uint32_t *) &a6->sin6_addr;
376 uint32_t *mask_elem = (uint32_t *) &mask6->sin6_addr;
377 uint32_t *net_elem = (uint32_t *) &net6->sin6_addr;
378 for (c = 0; c < 4; c++)
379 if ((addr_elem[c] & mask_elem[c]) != net_elem[c])
393 "`%s' is in network `%s'\n",
430 if (NULL !=
is->interface_task)
433 is->interface_task = NULL;
static struct GNUNET_TESTING_Interpreter * is
static char * name
Name (label) of the records to list.
static char * res
Currently read line or NULL on EOF.
static uint32_t type
Type string converted to DNS type value.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_log_from(kind, comp,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
void GNUNET_NT_scanner_done(struct GNUNET_NT_InterfaceScanner *is)
Client is done with the interface scanner, release resources.
struct GNUNET_NT_InterfaceScanner * GNUNET_NT_scanner_init()
Initialize the interface scanner.
enum GNUNET_NetworkType GNUNET_NT_scanner_get_type(struct GNUNET_NT_InterfaceScanner *is, const struct sockaddr *addr, socklen_t addrlen)
Returns where the address is located: LAN or WAN or ...
const char * GNUNET_NT_to_string(enum GNUNET_NetworkType net)
Convert a enum GNUNET_NetworkType to a string.
@ GNUNET_NT_WLAN
Wireless LAN (i.e.
@ GNUNET_NT_WAN
Wide area network (i.e.
@ GNUNET_NT_UNSPECIFIED
Category of last resort.
@ GNUNET_NT_LAN
Local area network.
@ GNUNET_NT_LOOPBACK
Loopback (same host).
@ GNUNET_NT_BT
Bluetooth LAN.
void GNUNET_OS_network_interfaces_list(GNUNET_OS_NetworkInterfaceProcessor proc, void *proc_cls)
Enumerate all network interfaces.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
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)
Function invoked for each interface found.
static void delete_networks(struct GNUNET_NT_InterfaceScanner *is)
Delete all entries from the current network list.
#define INTERFACE_PROCESSING_INTERVAL
How frequently do we scan the interfaces for changes to the addresses?
static void get_addresses(void *cls)
Periodically get list of network addresses from our interfaces.
Handle to the interface scanner.
struct NT_Network * net_head
Head of LAN networks list.
struct NT_Network * net_tail
Tail of LAN networks list.
struct GNUNET_SCHEDULER_Task * interface_task
Task for periodically refreshing our LAN network list.
Entry in list of pending tasks.
We keep a list of our local networks so we can answer LAN vs.
struct NT_Network * next
Kept in a DLL.
socklen_t length
How long are network and netmask?
struct sockaddr * network
Network address.
struct NT_Network * prev
Kept in a DLL.
struct sockaddr * netmask
Netmask to determine what is in the LAN.