netif.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
3  * Copyright (C) 2017 Freie Universität Berlin
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
33 #ifndef NET_NETIF_H
34 #define NET_NETIF_H
35 
36 #include <stdint.h>
37 #include <string.h>
38 #include <unistd.h>
39 
40 #include "list.h"
41 #include "net/netopt.h"
42 #include "net/ipv6.h"
43 
44 #ifdef MODULE_NETSTATS_NEIGHBOR
45 #include "cib.h"
46 #include "net/netstats.h"
47 #endif
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
61 #ifndef CONFIG_NETIF_NAMELENMAX
62 #define CONFIG_NETIF_NAMELENMAX (8U)
63 #endif
71 typedef struct {
73 #ifdef MODULE_NETSTATS_NEIGHBOR
74  netstats_nb_table_t neighbors;
75 #endif
76 } netif_t;
77 
89 netif_t *netif_iter(const netif_t *last);
90 
107 int netif_get_name(const netif_t *netif, char *name);
108 
117 int16_t netif_get_id(const netif_t *netif);
118 
130 netif_t *netif_get_by_name_buffer(const char *name, size_t name_len);
131 
144 static inline netif_t *netif_get_by_name(const char *name)
145 {
146  return netif_get_by_name_buffer(name, strlen(name));
147 }
148 
158 
173 int netif_get_opt(const netif_t *netif, netopt_t opt, uint16_t context,
174  void *value, size_t max_len);
175 
190 int netif_set_opt(const netif_t *netif, netopt_t opt, uint16_t context,
191  void *value, size_t value_len);
192 
204 
213 static inline ssize_t netif_get_ipv6(netif_t *netif, ipv6_addr_t *dest,
214  size_t numof)
215 {
216  int res = netif_get_opt(netif, NETOPT_IPV6_ADDR, 0, dest, sizeof(*dest) * numof);
217  if (res < 0) {
218  /* standard says at ssize_t's value range is [-1, SSIZE_MAX], so do
219  * not rely on smaller numbers that -1 being passed through correctly */
220  return -1;
221  }
222 
223  return res / sizeof(*dest);
224 }
225 
233 ssize_t netifs_get_ipv6(ipv6_addr_t *dest, size_t numof);
234 
248 void netif_print_ipv6(netif_t *netif, const char *separator);
249 
262 void netifs_print_ipv6(const char *separator);
263 
264 #ifdef __cplusplus
265 }
266 #endif
267 
268 #endif /* NET_NETIF_H */
Circular integer buffer interface.
int netif_get_name(const netif_t *netif, char *name)
Gets name of an interface.
netif_t * netif_get_by_id(int16_t id)
Gets interface by a numeric identifier.
netif_t * netif_iter(const netif_t *last)
Iterator for the interfaces.
static netif_t * netif_get_by_name(const char *name)
Gets interface by name.
Definition: netif.h:144
void netifs_print_ipv6(const char *separator)
Print the IPv6 address(es) of all interface.
void netif_print_ipv6(netif_t *netif, const char *separator)
Print the IPv6 address(es) of the given interface.
netif_t * netif_get_by_name_buffer(const char *name, size_t name_len)
Gets interface by name, from a buffer.
static ssize_t netif_get_ipv6(netif_t *netif, ipv6_addr_t *dest, size_t numof)
Get IPv6 address(es) of the given interface.
Definition: netif.h:213
int netif_register(netif_t *netif)
Registers a network interface in the global interface list.
ssize_t netifs_get_ipv6(ipv6_addr_t *dest, size_t numof)
Get IPv6 address(es) of all interfaces.
int netif_get_opt(const netif_t *netif, netopt_t opt, uint16_t context, void *value, size_t max_len)
Gets option from an interface.
int netif_set_opt(const netif_t *netif, netopt_t opt, uint16_t context, void *value, size_t value_len)
Sets option to an interface.
int16_t netif_get_id(const netif_t *netif)
Gets the numeric identifier of an interface.
netopt_t
Global list of configuration options available throughout the network stack, e.g.
Definition: netopt.h:45
@ NETOPT_IPV6_ADDR
(ipv6_addr_t[]) get IPv6 addresses of an interface as array of ipv6_addr_t or add an IPv6 address as ...
Definition: netopt.h:136
Definition of net statistics.
IPv6 include gathering header.
Intrusive linked list.
Definition of global configuration options.
List node structure.
Definition: list.h:40
Network interface descriptor.
Definition: netif.h:71
list_node_t node
Pointer to the next interface.
Definition: netif.h:72
L2 Peer Info struct.
Definition: netstats.h:104
Data type to represent an IPv6 address.
Definition: addr.h:72