Common network interface API.
More...
Common network interface API.
This allows access to network interfaces regardless of the network stack implementation. The network stack must provide
- A definition for
netif_get_name
- A definition for
netif_get_opt
- A definition for
netif_set_opt
The network stack should also register each interface via netif_register
.
|
file | netif.h |
| Common network interface API definitions.
|
|
|
netif_t * | netif_iter (const netif_t *last) |
| Iterator for the interfaces.
|
|
int | netif_get_name (const netif_t *netif, char *name) |
| Gets name of an interface.
|
|
int16_t | netif_get_id (const netif_t *netif) |
| Gets the numeric identifier of an interface.
|
|
netif_t * | netif_get_by_name_buffer (const char *name, size_t name_len) |
| Gets interface by name, from a buffer.
|
|
static netif_t * | netif_get_by_name (const char *name) |
| Gets interface by name.
|
|
netif_t * | netif_get_by_id (int16_t id) |
| Gets interface by a numeric identifier.
|
|
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.
|
|
int | netif_register (netif_t *netif) |
| Registers a network interface in the global interface list.
|
|
static ssize_t | netif_get_ipv6 (netif_t *netif, ipv6_addr_t *dest, size_t numof) |
| Get IPv6 address(es) of the given interface.
|
|
ssize_t | netifs_get_ipv6 (ipv6_addr_t *dest, size_t numof) |
| Get IPv6 address(es) of all interfaces.
|
|
void | netif_print_ipv6 (netif_t *netif, const char *separator) |
| Print the IPv6 address(es) of the given interface.
|
|
void | netifs_print_ipv6 (const char *separator) |
| Print the IPv6 address(es) of all interface.
|
|
◆ netif_get_by_id()
netif_t * netif_get_by_id |
( |
int16_t |
id | ) |
|
Gets interface by a numeric identifier.
- Parameters
-
[in] | id | A numeric identifier. |
- Returns
- The interface on success.
-
NULL if no interface with identifier
id
.
◆ netif_get_by_name()
static netif_t * netif_get_by_name |
( |
const char * |
name | ) |
|
|
inlinestatic |
Gets interface by name.
- Precondition
name != NULL
- Parameters
-
[in] | name | The name of an interface as a zero-terminated. Must not be NULL . |
- Returns
- The interface on success.
-
NULL if no interface is named
name
.
Definition at line 144 of file netif.h.
◆ netif_get_by_name_buffer()
netif_t * netif_get_by_name_buffer |
( |
const char * |
name, |
|
|
size_t |
name_len |
|
) |
| |
Gets interface by name, from a buffer.
- Precondition
name != NULL
- Parameters
-
[in] | name | The name of an interface as an array of chars. Must not be NULL . |
[in] | name_len | Number of characters in name . |
- Returns
- Pointer to the interface that matches the name
- Return values
-
NULL | if no interface is named name . |
◆ netif_get_id()
int16_t netif_get_id |
( |
const netif_t * |
netif | ) |
|
Gets the numeric identifier of an interface.
- Parameters
-
[in] | netif | A network interface. |
- Returns
- The numeric identifier of an interface
-
-1 if
netif
is not registered
◆ netif_get_ipv6()
Get IPv6 address(es) of the given interface.
- Parameters
-
[in] | netif | Interface to get the IPv6 address(es) from |
[out] | dest | Array of IPv6 addresses to write to |
[in] | numof | Size of dest in array elements (not in bytes!) |
- Return values
-
- Returns
- Number of addresses written to
dest
Definition at line 213 of file netif.h.
◆ netif_get_name()
int netif_get_name |
( |
const netif_t * |
netif, |
|
|
char * |
name |
|
) |
| |
Gets name of an interface.
- Precondition
name != NULL
-
name holds at least CONFIG_NETIF_NAMELENMAX characters
- Note
- Supposed to be implemented by the networking module.
name
must be zero-terminated in the result!
- Parameters
-
[in] | netif | A network interface. |
[out] | name | The name of the interface. Must not be NULL . Must at least hold CONFIG_NETIF_NAMELENMAX bytes. |
- Returns
- length of
name
on success
◆ netif_get_opt()
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.
- Note
- Supposed to be implemented by the networking module
- Parameters
-
[in] | netif | A network interface. |
[in] | opt | Option type. |
[in] | context | (Optional) context to the given option |
[out] | value | Pointer to store the option's value in. |
[in] | max_len | Maximal amount of byte that fit into value . |
- Returns
- Number of bytes written to
value
.
-
< 0
on error, 0 on success.
◆ netif_iter()
Iterator for the interfaces.
Returns interface after last
. To start use last == NULL
.
- Parameters
-
[in] | last | The previous interface. Use NULL to start iteration. |
- Returns
- next network interface.
-
NULL, if there is no interface after
last
◆ netif_print_ipv6()
void netif_print_ipv6 |
( |
netif_t * |
netif, |
|
|
const char * |
separator |
|
) |
| |
Print the IPv6 address(es) of the given interface.
- Parameters
-
[in] | netif | Interface to print the IPv6 address(es) of |
[in] | separator | Separator to print between the IPv6 addresses |
Usage:
printf(
"{\"IPv6 addresses\": [\"");
puts("\"]}");
#define printf(...)
A wrapper for the printf() function that passes arguments through unmodified, but fails to compile if...
void netif_print_ipv6(netif_t *netif, const char *separator)
Print the IPv6 address(es) of the given interface.
◆ netif_register()
int netif_register |
( |
netif_t * |
netif | ) |
|
Registers a network interface in the global interface list.
- Note
- This functions should be called when initializing an interface.
- Parameters
-
[in] | netif | Interface to be registered |
- Returns
- 0 on success
-
-EINVAL if
netif
is NULL.
◆ netif_set_opt()
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.
- Note
- Supposed to be implemented by the networking module
- Parameters
-
[in] | netif | A network interface. |
[in] | opt | Option type. |
[in] | context | (Optional) context to the given option |
[in] | value | Pointer to store the option's value in. |
[in] | value_len | The length of value . |
- Returns
- Number of bytes used from
value
.
-
< 0
on error, 0 on success.
◆ netifs_get_ipv6()
ssize_t netifs_get_ipv6 |
( |
ipv6_addr_t * |
dest, |
|
|
size_t |
numof |
|
) |
| |
Get IPv6 address(es) of all interfaces.
- Parameters
-
[out] | dest | Array of IPv6 addresses to write to |
[in] | numof | Size of dest in array elements (not in bytes!) |
- Return values
-
- Returns
- Number of addresses written to
dest
◆ netifs_print_ipv6()
void netifs_print_ipv6 |
( |
const char * |
separator | ) |
|
Print the IPv6 address(es) of all interface.
- Parameters
-
[in] | separator | Separator to print between the IPv6 addresses |
Usage:
printf(
"{\"IPv6 addresses\": [\"");
puts("\"]}");
void netifs_print_ipv6(const char *separator)
Print the IPv6 address(es) of all interface.