netif.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2016 Kaspar Schleiser <kaspar@schleiser.de>
3  * SPDX-FileCopyrightText: 2017 Freie Universität Berlin
4  * SPDX-License-Identifier: LGPL-2.1-only
5  */
6 
7 #pragma once
8 
33 #include <stdint.h>
34 #include <string.h>
35 #include <unistd.h>
36 
37 #include "list.h"
38 #include "net/netopt.h"
39 #include "net/ipv6.h"
40 
41 #ifdef MODULE_NETSTATS_NEIGHBOR
42 #include "cib.h"
43 #include "net/netstats.h"
44 #endif
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
58 #ifndef CONFIG_NETIF_NAMELENMAX
59 #define CONFIG_NETIF_NAMELENMAX (8U)
60 #endif
68 typedef struct {
70 #ifdef MODULE_NETSTATS_NEIGHBOR
71  netstats_nb_table_t neighbors;
72 #endif
73 } netif_t;
74 
86 netif_t *netif_iter(const netif_t *last);
87 
104 int netif_get_name(const netif_t *netif, char *name);
105 
114 int16_t netif_get_id(const netif_t *netif);
115 
127 netif_t *netif_get_by_name_buffer(const char *name, size_t name_len);
128 
141 static inline netif_t *netif_get_by_name(const char *name)
142 {
143  return netif_get_by_name_buffer(name, strlen(name));
144 }
145 
155 
170 int netif_get_opt(const netif_t *netif, netopt_t opt, uint16_t context,
171  void *value, size_t max_len);
172 
187 int netif_set_opt(const netif_t *netif, netopt_t opt, uint16_t context,
188  void *value, size_t value_len);
189 
201 
210 static inline ssize_t netif_get_ipv6(netif_t *netif, ipv6_addr_t *dest,
211  size_t numof)
212 {
213  int res = netif_get_opt(netif, NETOPT_IPV6_ADDR, 0, dest, sizeof(*dest) * numof);
214  if (res < 0) {
215  /* standard says at ssize_t's value range is [-1, SSIZE_MAX], so do
216  * not rely on smaller numbers that -1 being passed through correctly */
217  return -1;
218  }
219 
220  return res / sizeof(*dest);
221 }
222 
230 ssize_t netifs_get_ipv6(ipv6_addr_t *dest, size_t numof);
231 
245 void netif_print_ipv6(netif_t *netif, const char *separator);
246 
259 void netifs_print_ipv6(const char *separator);
260 
261 #ifdef __cplusplus
262 }
263 #endif
264 
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:141
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:210
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:41
@ 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:132
Definition of net statistics.
IPv6 include gathering header.
Intrusive linked list.
Definition of global configuration options.
List node structure.
Definition: list.h:36
Network interface descriptor.
Definition: netif.h:68
list_node_t node
Pointer to the next interface.
Definition: netif.h:69
L2 Peer Info struct.
Definition: netstats.h:100
Data type to represent an IPv6 address.
Definition: addr.h:64