5.6. network_interface — Network interface

The network interface module has a list of all network interfaces and their states.

Network interface modules:


Source code: src/inet/network_interface.h, src/inet/network_interface.c

Test coverage: src/inet/network_interface.c


Typedefs

typedef int(* network_interface_start_t)(struct network_interface_t *netif_p)
typedef int(* network_interface_stop_t)(struct network_interface_t *netif_p)
typedef int(* network_interface_is_up_t)(struct network_interface_t *netif_p)
typedef int(* network_interface_get_ip_address_t)(struct network_interface_t *netif_p, struct inet_ip_addr_t *addr_p)

Functions

int network_interface_module_init(void)

Initialize the network interface module. This function must be called before calling any other function in this module.

The module will only be initialized once even if this function is called multiple times.

Return
zero(0) or negative error code.

int network_interface_add(struct network_interface_t *netif_p)

Add given network interface to the IP stack.

Return
zero(0) or negative error code.
Parameters
  • netif_p -

    Network interface to add.

int network_interface_start(struct network_interface_t *netif_p)

Enable given network interface. Use network_interface_is_up() to check if the interface is connected.

Return
zero(0) or negative error code.
Parameters
  • netif_p -

    Network interface to enable.

int network_interface_is_up(struct network_interface_t *netif_p)

Get the connection status of given network interface.

Return
true(1) if the network interface is up, false(0) is it is down, and otherwise negative error code.
Parameters
  • netif_p -

    Network interface to get the connection status of.

struct network_interface_t *network_interface_get_by_name(const char *name_p)

Search the list of network interfaces for an interface with given name and return it.

Return
Found network interface or NULL if it was not found.
Parameters
  • name_p -

    Name of the network interface to find.

int network_interface_set_ip_address(struct network_interface_t *netif_p, struct inet_ip_addr_t *addr_p)

Get the ip address of given network interface.

Return
zero(0) or negative error code.
Parameters
  • netif_p -

    Network interface to get the ip address of.

int network_interface_get_ip_address(struct network_interface_t *netif_p, struct inet_ip_addr_t *addr_p)

Get the ip address of given network interface.

Return
zero(0) or negative error code.
Parameters
  • netif_p -

    Network interface to get the ip address of.

struct network_interface_t

Public Members

struct netif netif
const char *name_p
struct inet_ip_addr_t ipaddr
struct inet_ip_addr_t netmask
struct inet_ip_addr_t gw
netif_init_fn init
network_interface_start_t start
network_interface_stop_t stop
network_interface_is_up_t is_up
network_interface_get_ip_address_t get_ip_address
struct network_interface_t *next_p