Loading...
Searching...
No Matches
ip-utils.h
Go to the documentation of this file.
#ifndef JANUS_IP_UTILS_H
#define JANUS_IP_UTILS_H
#include <ifaddrs.h>
#include <netinet/in.h>
typedef enum janus_network_query_options {
janus_network_query_options_none = 0,
janus_network_query_options_name = 1,
janus_network_query_options_ipv4 = 2,
janus_network_query_options_ipv6 = 4,
janus_network_query_options_any_ip = 6,
janus_network_query_options_any = 7
} janus_network_query_options;
typedef struct janus_network_query_config {
const char *device_name;
janus_network_query_options mode;
struct in_addr ipv4;
struct in6_addr ipv6;
} janus_network_query_config;
typedef struct janus_network_address {
int family;
union {
struct in_addr ipv4;
struct in6_addr ipv6;
};
} janus_network_address;
typedef struct janus_network_address_string_buffer {
int family;
union {
char ipv4[INET_ADDRSTRLEN];
char ipv6[INET6_ADDRSTRLEN];
};
} janus_network_address_string_buffer;
int janus_network_prepare_device_query(const char *user_value, const janus_network_query_options query_mode, janus_network_query_config *query);
int janus_network_prepare_device_query_default(const char *user_value, janus_network_query_config *query);
const struct ifaddrs *janus_network_query_devices(const struct ifaddrs *ifas, const janus_network_query_config *query);
int janus_network_get_devices_ipv4(const struct ifaddrs *ifa, const janus_network_query_config *query, struct in_addr *result);
int janus_network_get_devices_ipv6(const struct ifaddrs *ifa, const janus_network_query_config *query, struct in6_addr *result);
int janus_network_get_device_address(const struct ifaddrs *ifa, janus_network_address *result);
void janus_network_address_nullify(janus_network_address *a);
int janus_network_address_is_null(const janus_network_address *a);
int janus_network_address_from_sockaddr(struct sockaddr *s, janus_network_address *a);
int janus_network_address_to_string_buffer(const janus_network_address *a, janus_network_address_string_buffer *buf);
void janus_network_address_string_buffer_nullify(janus_network_address_string_buffer *b);
int janus_network_address_string_buffer_is_null(const janus_network_address_string_buffer *b);
const char *janus_network_address_string_from_buffer(const janus_network_address_string_buffer *b);
int janus_network_string_is_valid_address(janus_network_query_options addr_type, const char *user_value);
int janus_network_string_to_address(janus_network_query_options addr_type, const char *user_value, janus_network_address *result);
int janus_network_lookup_interface(const struct ifaddrs *ifas, const char *iface, janus_network_address *result);
int janus_network_detect_local_ip(janus_network_query_options addr_type, janus_network_address *result);
char *janus_network_detect_local_ip_as_string(janus_network_query_options addr_type);
#endif
janus_network_get_devices_ipv4
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.
Definition ip-utils.c:115
janus_network_query_options
janus_network_query_options
Definition ip-utils.h:27
janus_network_query_options_ipv6
@ janus_network_query_options_ipv6
Definition ip-utils.h:31
janus_network_query_options_ipv4
@ janus_network_query_options_ipv4
Definition ip-utils.h:30
janus_network_query_options_none
@ janus_network_query_options_none
Definition ip-utils.h:28
janus_network_query_options_any_ip
@ janus_network_query_options_any_ip
Definition ip-utils.h:32
janus_network_query_options_name
@ janus_network_query_options_name
Definition ip-utils.h:29
janus_network_query_options_any
@ janus_network_query_options_any
Definition ip-utils.h:33
janus_network_get_devices_ipv6
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.
Definition ip-utils.c:133
janus_network_address_string_buffer_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.
Definition ip-utils.c:207
janus_network_detect_local_ip
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.
Definition ip-utils.c:262
janus_network_string_is_valid_address
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.
Definition ip-utils.c:219
janus_network_lookup_interface
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.
Definition ip-utils.c:241
janus_network_address_string_buffer_nullify
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.
Definition ip-utils.c:200
janus_network_get_device_address
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.
Definition ip-utils.c:141
janus_network_query_devices
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,...
Definition ip-utils.c:73
janus_network_address_is_null
int janus_network_address_is_null(const janus_network_address *a)
Test if a given network address is null-valued.
Definition ip-utils.c:165
janus_network_address_string_from_buffer
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.
Definition ip-utils.c:211
janus_network_string_to_address
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.
Definition ip-utils.c:224
janus_network_prepare_device_query_default
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...
Definition ip-utils.c:106
janus_network_detect_local_ip_as_string
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.
Definition ip-utils.c:316
janus_network_address_from_sockaddr
int janus_network_address_from_sockaddr(struct sockaddr *s, janus_network_address *a)
Convert a struct sockaddr to a janus_network_address.
Definition ip-utils.c:169
janus_network_address_nullify
void janus_network_address_nullify(janus_network_address *a)
Set the given network address to a null/nil value.
Definition ip-utils.c:158
janus_network_address_to_string_buffer
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 add...
Definition ip-utils.c:186
janus_network_prepare_device_query
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.
Definition ip-utils.c:83
janus_network_address_string_buffer
Structure to hold human readable forms of network addresses in a tagged union which should be IPv4 an...
Definition ip-utils.h:71
janus_network_address_string_buffer::family
int family
Definition ip-utils.h:75
janus_network_address_string_buffer::ipv6
char ipv6[INET6_ADDRSTRLEN]
Definition ip-utils.h:78
janus_network_address_string_buffer::ipv4
char ipv4[INET_ADDRSTRLEN]
Definition ip-utils.h:77
janus_network_address
Structure to hold network addresses in a tagged union which should be IPv4 and IPv6 compatible....
Definition ip-utils.h:53
janus_network_address::ipv4
struct in_addr ipv4
Definition ip-utils.h:59
janus_network_address::ipv6
struct in6_addr ipv6
Definition ip-utils.h:60
janus_network_address::family
int family
Definition ip-utils.h:57
janus_network_query_config
Internal object representation of a network device query (configuration).
Definition ip-utils.h:39
janus_network_query_config::ipv4
struct in_addr ipv4
Definition ip-utils.h:42
janus_network_query_config::device_name
const char * device_name
Definition ip-utils.h:40
janus_network_query_config::mode
janus_network_query_options mode
Definition ip-utils.h:41
janus_network_query_config::ipv6
struct in6_addr ipv6
Definition ip-utils.h:43