Network interfaces

Common network interface API. More...

Detailed Description

Common network interface API.

This allows access to network interfaces regardless of the network stack implementation. The network stack must provide

The network stack should also register each interface via netif_register.

Modules

 Network interfaces compile configurations
 

Files

file  netif.h
 Common network interface API definitions.
 

Data Structures

struct  netif_t
 Network interface descriptor. More...
 

Functions

netif_tnetif_iter (const netif_t *last)
 Iterator for the interfaces. More...
 
int netif_get_name (netif_t *netif, char *name)
 Gets name of an interface. More...
 
int16_t netif_get_id (const netif_t *netif)
 Gets the numeric identifier of an interface. More...
 
netif_tnetif_get_by_name_buffer (const char *name, size_t name_len)
 Gets interface by name, from a buffer. More...
 
static netif_tnetif_get_by_name (const char *name)
 Gets interface by name. More...
 
netif_tnetif_get_by_id (int16_t id)
 Gets interface by a numeric identifier. More...
 
int netif_get_opt (netif_t *netif, netopt_t opt, uint16_t context, void *value, size_t max_len)
 Gets option from an interface. More...
 
int netif_set_opt (netif_t *netif, netopt_t opt, uint16_t context, void *value, size_t value_len)
 Sets option to an interface. More...
 
int netif_register (netif_t *netif)
 Registers a network interface in the global interface list. More...
 
static ssize_t netif_get_ipv6 (netif_t *netif, ipv6_addr_t *dest, size_t numof)
 Get IPv6 address(es) of the given interface. More...
 
ssize_t netifs_get_ipv6 (ipv6_addr_t *dest, size_t numof)
 Get IPv6 address(es) of all interfaces. More...
 
void netif_print_ipv6 (netif_t *netif, const char *separator)
 Print the IPv6 address(es) of the given interface. More...
 
void netifs_print_ipv6 (const char *separator)
 Print the IPv6 address(es) of all interface. More...
 

Function Documentation

◆ netif_get_by_id()

netif_t* netif_get_by_id ( int16_t  id)

Gets interface by a numeric identifier.

Parameters
[in]idA 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]nameThe 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]nameThe name of an interface as an array of chars. Must not be NULL.
[in]name_lenNumber of characters in name.
Returns
Pointer to the interface that matches the name
Return values
NULLif 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]netifA network interface.
Returns
The numeric identifier of an interface
-1 if netif is not registered

◆ netif_get_ipv6()

static ssize_t netif_get_ipv6 ( netif_t netif,
ipv6_addr_t dest,
size_t  numof 
)
inlinestatic

Get IPv6 address(es) of the given interface.

Parameters
[in]netifInterface to get the IPv6 address(es) from
[out]destArray of IPv6 addresses to write to
[in]numofSize of dest in array elements (not in bytes!)
Return values
-1Failed
Returns
Number of addresses written to dest

Definition at line 213 of file netif.h.

◆ netif_get_name()

int netif_get_name ( 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]netifA network interface.
[out]nameThe 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 ( 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]netifA network interface.
[in]optOption type.
[in]context(Optional) context to the given option
[out]valuePointer to store the option's value in.
[in]max_lenMaximal amount of byte that fit into value.
Returns
Number of bytes written to value.
< 0 on error, 0 on success.

◆ netif_iter()

netif_t* netif_iter ( const netif_t last)

Iterator for the interfaces.

Returns interface after last. To start use last == NULL.

Parameters
[in]lastThe 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]netifInterface to print the IPv6 address(es) of
[in]separatorSeparator to print between the IPv6 addresses

Usage:

// print IPv6 addrs of netif as JSON
printf("{\"IPv6 addresses\": [\"");
netif_print_ipv6(netif, "\", \"");
puts("\"]}");
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]netifInterface to be registered
Returns
0 on success
-EINVAL if netif is NULL.

◆ netif_set_opt()

int netif_set_opt ( 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]netifA network interface.
[in]optOption type.
[in]context(Optional) context to the given option
[in]valuePointer to store the option's value in.
[in]value_lenThe 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]destArray of IPv6 addresses to write to
[in]numofSize of dest in array elements (not in bytes!)
Return values
-1Failed
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]separatorSeparator to print between the IPv6 addresses

Usage:

// print all IPv6 addrs as JSON
printf("{\"IPv6 addresses\": [\"");
puts("\"]}");
void netifs_print_ipv6(const char *separator)
Print the IPv6 address(es) of all interface.