Soletta™ Framework
|
Network module provides a way to handle network link interfaces. More...
Data Structures | |
struct | sol_network_link |
Structure to represent a network link. More... | |
struct | sol_network_link_addr |
Structure to represent a network address, both IPv6 and IPv4 are valid. More... | |
Macros | |
#define | SOL_BLUETOOTH_ADDR_STRLEN 18 |
String size of a Bluetooth address. More... | |
#define | SOL_NETWORK_INET_ADDR_STR_LEN 48 |
String size of an IPv4/v6 address. More... | |
#define | SOL_NETWORK_LINK_CHECK_VERSION(link_,...) |
Macro used to check if a struct struct sol_network_link has the expected API version. More... | |
Typedefs | |
typedef struct sol_network_hostname_pending | sol_network_hostname_pending |
A handle returned by sol_network_get_hostname_address_info() More... | |
typedef struct sol_network_link | sol_network_link |
Structure to represent a network link. More... | |
typedef struct sol_network_link_addr | sol_network_link_addr |
Structure to represent a network address, both IPv6 and IPv4 are valid. More... | |
Enumerations | |
enum | sol_network_bt_addr_type { SOL_NETWORK_BT_ADDR_BASIC_RATE, SOL_NETWORK_BT_ADDR_LE_PUBLIC, SOL_NETWORK_BT_ADDR_LE_RANDOM } |
Type of a Bluetooth address. More... | |
enum | sol_network_event { SOL_NETWORK_LINK_ADDED, SOL_NETWORK_LINK_REMOVED, SOL_NETWORK_LINK_CHANGED } |
Type of events generated for a network link. More... | |
enum | sol_network_family { SOL_NETWORK_FAMILY_UNSPEC, SOL_NETWORK_FAMILY_INET, SOL_NETWORK_FAMILY_INET6, SOL_NETWORK_FAMILY_BLUETOOTH, SOL_NETWORK_FAMILY_BLUETOOTH_RFCOMM, SOL_NETWORK_FAMILY_BLUETOOTH_L2CAP } |
Type of a network address. More... | |
enum | sol_network_link_flags { SOL_NETWORK_LINK_UP = (1 << 0), SOL_NETWORK_LINK_BROADCAST = (1 << 1), SOL_NETWORK_LINK_LOOPBACK = (1 << 2), SOL_NETWORK_LINK_MULTICAST = (1 << 3), SOL_NETWORK_LINK_RUNNING = (1 << 4) } |
Bitwise OR-ed flags to represent the status of a sol_network_link. More... | |
Functions | |
const struct sol_vector * | sol_network_get_available_links (void) |
Retrieve the available network links on a system. More... | |
struct sol_network_hostname_pending * | sol_network_get_hostname_address_info (const struct sol_str_slice hostname, enum sol_network_family family, void(*host_info_cb)(void *data, const struct sol_str_slice hostname, const struct sol_vector *addrs_list), const void *data) |
Gets a hostname address info. More... | |
int | sol_network_hostname_pending_cancel (struct sol_network_hostname_pending *handle) |
Cancels a request to get the hostname info. More... | |
static bool | sol_network_link_addr_eq (const struct sol_network_link_addr *a, const struct sol_network_link_addr *b) |
Checks if two address are equal. More... | |
static bool | sol_network_link_addr_eq_full (const struct sol_network_link_addr *a, const struct sol_network_link_addr *b, bool compare_ports) |
Checks if two address are equal - possibly including the port field. More... | |
const struct sol_network_link_addr * | sol_network_link_addr_from_str (struct sol_network_link_addr *addr, const char *buf) |
Converts a string address to sol_network_link_addr . More... | |
const char * | sol_network_link_addr_to_str (const struct sol_network_link_addr *addr, struct sol_buffer *buf) |
Converts a sol_network_link_addr to a string. More... | |
int | sol_network_link_down (uint16_t link_index) |
Sets a network link down. More... | |
char * | sol_network_link_get_name (const struct sol_network_link *link) |
Gets the name of a network link. More... | |
int | sol_network_link_up (uint16_t link_index) |
Sets a network link up. More... | |
int | sol_network_subscribe_events (void(*cb)(void *data, const struct sol_network_link *link, enum sol_network_event event), const void *data) |
Subscribes to receive network link events. More... | |
int | sol_network_unsubscribe_events (void(*cb)(void *data, const struct sol_network_link *link, enum sol_network_event event), const void *data) |
Stops receiving network link events. More... | |
Network module provides a way to handle network link interfaces.
It makes it possible to observe events, to inquire available links and to set their states.
#define SOL_BLUETOOTH_ADDR_STRLEN 18 |
String size of a Bluetooth address.
Referenced by found_device(), on_connect(), and on_disconnect().
#define SOL_NETWORK_INET_ADDR_STR_LEN 48 |
String size of an IPv4/v6 address.
Referenced by _on_network_event(), found_resource(), found_resource_print(), got_get_response(), print_response(), reply_cb(), request_cb(), and resource_notify().
#define SOL_NETWORK_LINK_CHECK_VERSION | ( | link_, | |
... | |||
) |
Macro used to check if a struct struct
sol_network_link has the expected API version.
In case it has wrong version, it'll return extra arguments passed to the macro.
A handle returned by sol_network_get_hostname_address_info()
This handle can be used to cancel the work of unfinished sol_network_get_hostname_address_info() calls, by calling sol_network_hostname_pending_cancel().
typedef struct sol_network_link sol_network_link |
Structure to represent a network link.
This struct contains the necessary information do deal with a network link. It has the state sol_network_link_flags, the index (the value used by the SO to identify the link) and its address sol_network_link_addr.
typedef struct sol_network_link_addr sol_network_link_addr |
Structure to represent a network address, both IPv6 and IPv4 are valid.
enum sol_network_event |
Type of events generated for a network link.
Enumerator | |
---|---|
SOL_NETWORK_LINK_ADDED | |
SOL_NETWORK_LINK_REMOVED | |
SOL_NETWORK_LINK_CHANGED |
enum sol_network_family |
Type of a network address.
Tells how an address should be interpreted.
Bitwise OR-ed flags to represent the status of a sol_network_link.
Enumerator | |
---|---|
SOL_NETWORK_LINK_UP | |
SOL_NETWORK_LINK_BROADCAST | |
SOL_NETWORK_LINK_LOOPBACK | |
SOL_NETWORK_LINK_MULTICAST | |
SOL_NETWORK_LINK_RUNNING |
const struct sol_vector* sol_network_get_available_links | ( | void | ) |
Retrieve the available network links on a system.
struct sol_network_hostname_pending* sol_network_get_hostname_address_info | ( | const struct sol_str_slice | hostname, |
enum sol_network_family | family, | ||
void(*)(void *data, const struct sol_str_slice hostname, const struct sol_vector *addrs_list) | host_info_cb, | ||
const void * | data | ||
) |
Gets a hostname address info.
This function will fetch the address of a given hostname. Since this may take some time to complete, this will be an asynchronous operation. When the address information is ready, host_info_cb
will be called with it. If an error happens or it was not possible to fetch the host address information, addrs_list
will be set to NULL
. The list addrs_list
will contain a set of sol_network_link_addr.
hostname | The hostname to get the address info. |
family | The family the returned addresses should be, pass SOL_NETWORK_FAMILY_UNSPEC to match them all. |
host_info_cb | A callback to be called with the address list. |
data | Data to host_info_cb . |
NULL
on error. int sol_network_hostname_pending_cancel | ( | struct sol_network_hostname_pending * | handle | ) |
Cancels a request to get the hostname info.
handle | The handle returned by sol_network_get_hostname_address_info |
|
inlinestatic |
Checks if two address are equal.
This function compares two addresses to see if they are the same.
a | The first address to be compared. |
b | The second address to be compared. |
true
if they are equal, otherwise false
. References sol_network_link_addr_eq_full().
Referenced by found_device().
|
inlinestatic |
Checks if two address are equal - possibly including the port field.
This function compares two addresses to see if they are the same.
a | The first address to be compared. |
b | The second address to be compared. |
compare_ports | Indicates if the port should be included in the comparison as well. |
true
if they are equal, otherwise false
. An IPv6 is Mapped into v4 when: First 80 bits are zero The next 16 bits are 0xffff
References sol_network_link_addr::addr, sol_network_link_addr::bt_addr, sol_network_link_addr::bt_type, sol_network_link_addr::family, sol_network_link_addr::in, sol_network_link_addr::in6, sol_network_link_addr::port, SOL_NETWORK_FAMILY_BLUETOOTH, SOL_NETWORK_FAMILY_INET, SOL_NETWORK_FAMILY_INET6, and sol_util_be16_to_cpu().
Referenced by sol_network_link_addr_eq().
const struct sol_network_link_addr* sol_network_link_addr_from_str | ( | struct sol_network_link_addr * | addr, |
const char * | buf | ||
) |
Converts a string address to sol_network_link_addr
.
addr | A valid address with the same family of the address given in buf . |
buf | The string with the address. |
NULL
on error.Referenced by main(), startup(), and startup_client().
const char* sol_network_link_addr_to_str | ( | const struct sol_network_link_addr * | addr, |
struct sol_buffer * | buf | ||
) |
Converts a sol_network_link_addr
to a string.
addr | The address to be converted. |
buf | The buffer where the converted string will be appended - It must be already initialized. |
NULL
on error.Referenced by _on_network_event(), found_device(), found_resource(), found_resource_print(), got_get_response(), on_connect(), on_disconnect(), print_response(), reply_cb(), request_cb(), and resource_notify().
int sol_network_link_down | ( | uint16_t | link_index | ) |
Sets a network link down.
This function sets a network link down, after this a link will not be able to get a network address.
link_index | The index of a sol_network_link structure. |
0
on success, -ENOSYS
on error.char* sol_network_link_get_name | ( | const struct sol_network_link * | link | ) |
Gets the name of a network link.
link | The sol_network_link structure which the name is desired. |
NULL
on error.Referenced by _match_link(), and _on_network_event().
int sol_network_link_up | ( | uint16_t | link_index | ) |
Sets a network link up.
This function sets a network link up, after this a link will be able to get a network address.
link_index | The index of a sol_network_link structure. |
true
on success, -errno
on error.int sol_network_subscribe_events | ( | void(*)(void *data, const struct sol_network_link *link, enum sol_network_event event) | cb, |
const void * | data | ||
) |
Subscribes to receive network link events.
This function register a callback given by the user that will be called when a network event (sol_network_event) occurrs in one link (sol_network_link).
cb | The callback used to notify the user. |
data | The user data given in the callback. |
true
on success, -errno
on errorReferenced by startup_network().
int sol_network_unsubscribe_events | ( | void(*)(void *data, const struct sol_network_link *link, enum sol_network_event event) | cb, |
const void * | data | ||
) |
Stops receiving network link events.
This function removes previous callbacks set (sol_network_subscribe_events()) to receive network events.
cb | The callback given on sol_network_subscribe_events. |
data | The data given on sol_network_subscribe_events. |
O
on success, -errno
on errorReferenced by shutdown_network().