Eris Linux A.P.I. 0.1
API to access Eris Linux system from a custom container
Loading...
Searching...
No Matches
NETWORK

Functions to setup network. More...

Functions

int eris_get_list_of_network_interfaces (char *buffer, size_t size)
 Get a list of network interfaces.
int eris_get_network_interface_status (const char *interface, char *buffer, size_t size)
 Get the status of a network interface.
int eris_set_network_interface_status (const char *interface, const char *status)
 Activate or disactivate a network interface.
int eris_get_network_interface_config (const char *interface, char *buffer, size_t size)
 Get the configuration of a network interface.
int eris_set_network_interface_config (const char *interface, const char *autoconf, const char *mode, const char *ip, const char *address, const char *netmask, const char *gateway)
 Set the configuration of a network interface.
int eris_get_nameserver_address (char *buffer, size_t size)
 Get the IP address of the Domain Name Server.
int eris_is_network_interface_wireless (const char *interface)
 Indicate whether a network interface is wireless or not.
int eris_scan_wifi (const char *interface, char *buffer, size_t size)
 Scan the available Wifi access points.
int eris_connect_wifi (const char *interface, const char *ssid, const char *password)
 Connect to a Wifi access point.
int eris_disconnect_wifi (void)
 Disconnect to any Wifi access points.
int eris_get_wifi_quality (const char *interface, char *buffer, size_t size)
 Get the Wifi connection quality.

Detailed Description

Functions to setup network.

Function Documentation

◆ eris_connect_wifi()

int eris_connect_wifi ( const char * interface,
const char * ssid,
const char * password )

Connect to a Wifi access point.

Parameters
interfaceThe name of the interface.
ssidThe identifier of the access point.
passwordThe passphrase to use to connect.
Returns
0 on success, -1 on error and errno is set appropriately.

◆ eris_disconnect_wifi()

int eris_disconnect_wifi ( void )

Disconnect to any Wifi access points.

Returns
0 on success, -1 on error and errno is set appropriately.

◆ eris_get_list_of_network_interfaces()

int eris_get_list_of_network_interfaces ( char * buffer,
size_t size )

Get a list of network interfaces.

Parameters
bufferThe buffer to fill with the list.
sizeThe size of the buffer.
Returns
0 on success, -1 on error and errno is set appropriately.

This function fills the provided buffer with the space-separated list of available network interfaces.

You can call is_network_interface_wireless() to distinguish between wired and wireless interfaces.

Example of use:

#include <liberis.h>
#include <stdio.h>
int main(void)
{
char list[512];
if (eris_list_network_interfaces(list, 512) != 0) {
return EXIT_FAILURE;
}
char *interface;
while ((interface = strtok(list, " ")) != NULL) {
printf("- %s", interface);
printf(" (wireless)");
printf("\n");
}
return EXIT_SUCCESS;
}
int eris_is_network_interface_wireless(const char *interface)
Indicate whether a network interface is wireless or not.

◆ eris_get_nameserver_address()

int eris_get_nameserver_address ( char * buffer,
size_t size )

Get the IP address of the Domain Name Server.

Parameters
bufferThe buffer to fill with the address.
sizeThe size of the buffer.
Returns
0 on success, -1 on error and errno is set appropriately.

Example of use:

char buffer[128];
if (eris_get_nameserver_address(buffer, 128) < 0)
return -1;
int eris_get_nameserver_address(char *buffer, size_t size)
Get the IP address of the Domain Name Server.

◆ eris_get_network_interface_config()

int eris_get_network_interface_config ( const char * interface,
char * buffer,
size_t size )

Get the configuration of a network interface.

Parameters
interfacceThe name of the interface considered.
bufferThe buffer to fill with the configuration.
sizeThe size of the buffer.
Returns
0 on success, -1 on error and errno is set appropriately.

The configuration stored in the buffer is a string with the following space-separated fields:

  • the interface name
  • atboot or ondemand depending whether the interface is automatically activated at boot
  • dhcp or static depending on the way to obtain IP address.
  • 4 or 6 depending on the IP version to use (only if the third field is static)
  • the IP address (only if the third field is static)
  • the subnet mask (only if the third field is static)
  • the gateway address to access Internet (only if the third field is static)
  • the address of the DNS name server (only if the third field is static)

◆ eris_get_network_interface_status()

int eris_get_network_interface_status ( const char * interface,
char * buffer,
size_t size )

Get the status of a network interface.

Parameters
interfaceThe name of the interface considered.
bufferThe buffer to fill with the status.
sizeThe size of the buffer.
Returns
0 on success, -1 on error and errno is set appropriately.

This function fills the provided buffer with "up" or "down" depending on the status of the interface.

◆ eris_get_wifi_quality()

int eris_get_wifi_quality ( const char * interface,
char * buffer,
size_t size )

Get the Wifi connection quality.

Parameters
interfaceThe name of the interface.
bufferThe buffer to fill with Wifi quality.
sizeThe maximum size of the buffer.
Returns
0 on success, -1 on error and errno is set appropriately.

This function fills the buffer with the a line containing 3 fields. For example:

link=70 level=-37 noise=-256

The values are:

  • link quality (percent)
  • signal level in dBm
  • noise level in dBm

◆ eris_is_network_interface_wireless()

int eris_is_network_interface_wireless ( const char * interface)

Indicate whether a network interface is wireless or not.

Parameters
interfacethe name of the interface.
Returns
1 if the interface is wireless, 0 if it is not, -1 on error and errno is set appropriately.

See list_network_interfaces() for an example of use.

◆ eris_scan_wifi()

int eris_scan_wifi ( const char * interface,
char * buffer,
size_t size )

Scan the available Wifi access points.

Parameters
interfaceThe name of the interface.
bufferThe buffer to fill with SSID of access points.
sizeThe maximum size of the buffer.
Returns
0 on success, -1 on error and errno is set appropriately.

This function fills the provided buffer with the line-separated list of SSID of available Wifi access points.

We choose to use \n as list spearator because SSIDs may contain most of the available characters, including spaces.

◆ eris_set_network_interface_config()

int eris_set_network_interface_config ( const char * interface,
const char * autoconf,
const char * mode,
const char * ip,
const char * address,
const char * netmask,
const char * gateway )

Set the configuration of a network interface.

Parameters
interfaceThe name of the interface considered.
activateatboot if the interface has to be activated at boot, ondemand otherwise.
modedhcp if the address is automatically affected or static otherwise.
ipipv4 or ipv6 depending of the IP address version (ignored if 3th field is dhcp).
addressIP address of the interface (ignored if 3th field is dhcp)
netmaskIP mask of the subnet (ignored if 3th field is dhcp)
gatewayIP address of the gateway (ignored if 3th field is dhcp)
Returns
0 on success, -1 on error and errno is set appropriately.

Example of use:

eris_set_network_interface_config("eth0", "atboot", "static", "ipv4", "192.168.1.1", "255.255.255.0", "192.168.1.254");
eris_set_network_interface_config("eth1", "ondemand", "dhcp", NULL, NULL, NULL, NULL);
int eris_set_network_interface_config(const char *interface, const char *autoconf, const char *mode, const char *ip, const char *address, const char *netmask, const char *gateway)
Set the configuration of a network interface.

◆ eris_set_network_interface_status()

int eris_set_network_interface_status ( const char * interface,
const char * status )

Activate or disactivate a network interface.

This function enables the interface if status is "up", or disables it if status is "down". Any other string than "up" or "down" is invalid and this function returns EINVAL in errno.

If the interface activation fails, the function will returns an error.

Parameters
interfaceThe name of the concerned interface.
statusThe desired status ("up" or "down").
Returns
0 on success, -1 on error and errno is set appropriately.