IP address related utility functions. More...
#include <errno.h>#include <sys/socket.h>#include <sys/types.h>#include <arpa/inet.h>#include <netdb.h>#include <net/if.h>#include <string.h>#include <unistd.h>#include <glib.h>#include "ip-utils.h"
Functions | |
| const struct ifaddrs * | janus_network_query_devices (const struct ifaddrs *ifa, const janus_network_query_config *query) |
Look up network devices matching the given query. The first matching device is returned, so to find all matching devices simply pass the ifa_next of the returned device in a subsequent call to this function to find more matches. More... | |
| int | janus_network_prepare_device_query (const char *user_value, const janus_network_query_options query_mode, janus_network_query_config *query) |
| Initialise a network device query. More... | |
| int | janus_network_prepare_device_query_default (const char *user_value, janus_network_query_config *query) |
Initialise a network device query with default query options. This function will Initialise the query to accept any supported match type. More... | |
| int | janus_network_get_devices_ipv4 (const struct ifaddrs *ifa, const janus_network_query_config *query, struct in_addr *result) |
| Copies the IPv4 address from a network inteface description to the given result structure. More... | |
| int | janus_network_get_devices_ipv6 (const struct ifaddrs *ifa, const janus_network_query_config *query, struct in6_addr *result) |
| Copies the IPv6 address from a network inteface description to the given result structure. More... | |
| int | janus_network_get_device_address (const struct ifaddrs *ifa, janus_network_address *result) |
| Copies the IP address from a network interface description to the given result structure. More... | |
| void | janus_network_address_nullify (janus_network_address *a) |
| Set the given network address to a null/nil value. More... | |
| int | janus_network_address_is_null (const janus_network_address *a) |
| Test if a given network address is null-valued. More... | |
| int | janus_network_address_from_sockaddr (struct sockaddr *s, janus_network_address *a) |
| Convert a struct sockaddr to a janus_network_address. More... | |
| int | janus_network_address_to_string_buffer (const janus_network_address *a, janus_network_address_string_buffer *buf) |
| Convert the given network address to a form which can be used to extract a human readable network address from. More... | |
| void | janus_network_address_string_buffer_nullify (janus_network_address_string_buffer *b) |
| Set the given network address string buffer to a null/nil value. More... | |
| int | janus_network_address_string_buffer_is_null (const janus_network_address_string_buffer *b) |
| Test if a given network address string buffer is null-valued. More... | |
| const char * | janus_network_address_string_from_buffer (const janus_network_address_string_buffer *b) |
| Extract the human readable representation of a network address from a given buffer. More... | |
| int | janus_network_string_is_valid_address (janus_network_query_options addr_type, const char *user_value) |
| Test if a given IP address string is a valid address of the specified type. More... | |
| int | janus_network_string_to_address (janus_network_query_options addr_type, const char *user_value, janus_network_address *result) |
| Convert an IP address string to a janus_network_address instance. More... | |
| int | janus_network_lookup_interface (const struct ifaddrs *ifas, const char *iface, janus_network_address *result) |
| Convert an interface name or IP address to a janus_network_address instance. More... | |
| int | janus_network_detect_local_ip (janus_network_query_options addr_type, janus_network_address *result) |
| Helper method to find a valid local IP address, that is an address that can be used to communicate. More... | |
| char * | janus_network_detect_local_ip_as_string (janus_network_query_options addr_type) |
| Wrapper to janus_network_detect_local_ip that returns a string instead. More... | |
IP address related utility functions.
| int janus_network_address_from_sockaddr | ( | struct sockaddr * | s, |
| janus_network_address * | a | ||
| ) |
Convert a struct sockaddr to a janus_network_address.
| s | The struct sockaddr to convert |
| a | The address to write to |
| int janus_network_address_is_null | ( | const janus_network_address * | a | ) |
Test if a given network address is null-valued.
| a | The address to check |
janus_network_address_nullify | void janus_network_address_nullify | ( | janus_network_address * | a | ) |
Set the given network address to a null/nil value.
| a | The address to nullify. Nothing is done if the pointer is NULL itself. |
janus_network_address_is_null | int janus_network_address_string_buffer_is_null | ( | const janus_network_address_string_buffer * | b | ) |
Test if a given network address string buffer is null-valued.
| b | The buffer to check |
| void janus_network_address_string_buffer_nullify | ( | janus_network_address_string_buffer * | b | ) |
Set the given network address string buffer to a null/nil value.
| b | The address to nullify. Nothing is done if the pointer is NULL itself. |
| const char* janus_network_address_string_from_buffer | ( | const janus_network_address_string_buffer * | b | ) |
Extract the human readable representation of a network address from a given buffer.
| b | The buffer containing the given network |
| int janus_network_address_to_string_buffer | ( | const janus_network_address * | a, |
| janus_network_address_string_buffer * | buf | ||
| ) |
Convert the given network address to a form which can be used to extract a human readable network address from.
| a | The address to convert |
| buf | A buffer to contain the human readable form. |
janus_network_address janus_network_address_string_buffer janus_network_address_string_from_buffer | int janus_network_detect_local_ip | ( | janus_network_query_options | addr_type, |
| janus_network_address * | result | ||
| ) |
Helper method to find a valid local IP address, that is an address that can be used to communicate.
| addr_type | The type of address you're interested in (janus_network_query_options_ipv4, janus_network_query_options_ipv6 or janus_network_query_options_any_ip) |
| result | Pointer to a valid janus_network_address instance that will contain the result |
| char* janus_network_detect_local_ip_as_string | ( | janus_network_query_options | addr_type | ) |
Wrapper to janus_network_detect_local_ip that returns a string instead.
| addr_type | The type of address you're interested in (janus_network_query_options_ipv4, janus_network_query_options_ipv6 or janus_network_query_options_any_ip) |
| int janus_network_get_device_address | ( | const struct ifaddrs * | ifa, |
| janus_network_address * | result | ||
| ) |
Copies the IP address from a network interface description to the given result structure.
janus_network_address | int janus_network_get_devices_ipv4 | ( | const struct ifaddrs * | ifa, |
| const janus_network_query_config * | query, | ||
| struct in_addr * | result | ||
| ) |
Copies the IPv4 address from a network inteface description to the given result structure.
| ifa | The network interface description to grab the IPv4 address from. It should be obtained with janus_network_query_devices(). |
| query | A description of the criteria to look for when determining whether or not a network interface is a match |
| result | Pointer to a structure to populate with the IPv4 address of the given network interface |
janus_network_query_devices | int janus_network_get_devices_ipv6 | ( | const struct ifaddrs * | ifa, |
| const janus_network_query_config * | query, | ||
| struct in6_addr * | result | ||
| ) |
Copies the IPv6 address from a network inteface description to the given result structure.
| ifa | The network interface description to grab the IPv6 address from. It should be obtained with janus_network_query_devices(). |
| query | A description of the criteria to look for when determining whether or not a network interface is a match |
| result | Pointer to a structure to populate with the IPv6 address of the given network interface |
janus_network_query_devices | int janus_network_lookup_interface | ( | const struct ifaddrs * | ifas, |
| const char * | iface, | ||
| janus_network_address * | result | ||
| ) |
Convert an interface name or IP address to a janus_network_address instance.
| ifas | The list of interfaces to look into (e.g., as returned from getifaddrs) |
| iface | The interface name or IP address to look for |
| result | Pointer to a valid janus_network_address instance that will contain the result |
| int janus_network_prepare_device_query | ( | const char * | user_value, |
| const janus_network_query_options | query_mode, | ||
| janus_network_query_config * | query | ||
| ) |
Initialise a network device query.
| user_value | The user-supplied string which is supposed to describe either the device name or its IP address. |
| query_mode | (A mask of) Options describing the supported types of matches which should be accepted when performing a look up with this query. This can be used to restrict the query to 'by device name' or 'IPv4 only' type searches. |
| query | The query object to configure. |
janus_network_query_options | int janus_network_prepare_device_query_default | ( | const char * | user_value, |
| janus_network_query_config * | query | ||
| ) |
Initialise a network device query with default query options. This function will Initialise the query to accept any supported match type.
| user_value | The user-supplied string which is supposed to describe either the device name or its IP address. |
| query | The query object to configure. |
| const struct ifaddrs* janus_network_query_devices | ( | const struct ifaddrs * | ifas, |
| const janus_network_query_config * | query | ||
| ) |
Look up network devices matching the given query. The first matching device is returned, so to find all matching devices simply pass the ifa_next of the returned device in a subsequent call to this function to find more matches.
| ifas | The first node of the list of network interfaces to search through. This should be obtained (indirectly) from getifaddrs(). |
| query | A description of the criteria to look for when determining whether or not a network interface is a match. |
NULL if no (further) match was found. | int janus_network_string_is_valid_address | ( | janus_network_query_options | addr_type, |
| const char * | user_value | ||
| ) |
Test if a given IP address string is a valid address of the specified type.
| addr_type | The type of address you're interested in (janus_network_query_options_ipv4, janus_network_query_options_ipv6 or janus_network_query_options_any_ip) |
| user_value | The IP address string to check |
| int janus_network_string_to_address | ( | janus_network_query_options | addr_type, |
| const char * | user_value, | ||
| janus_network_address * | result | ||
| ) |
Convert an IP address string to a janus_network_address instance.
| addr_type | The type of address you're interested in (janus_network_query_options_ipv4, janus_network_query_options_ipv6 or janus_network_query_options_any_ip) |
| user_value | The IP address string to check |
| result | Pointer to a valid janus_network_address instance that will contain the result |