Fork me on GitHub
Loading...
Searching...
No Matches
ip-utils.h
Go to the documentation of this file.
1
17#ifndef JANUS_IP_UTILS_H
18#define JANUS_IP_UTILS_H
19
20#include <ifaddrs.h>
21#include <netinet/in.h>
22
23
35
45
53typedef struct janus_network_address {
57 int family;
58 union {
59 struct in_addr ipv4;
60 struct in6_addr ipv6;
61 };
63
75 int family;
76 union {
77 char ipv4[INET_ADDRSTRLEN];
78 char ipv6[INET6_ADDRSTRLEN];
79 };
81
92int janus_network_prepare_device_query(const char *user_value, const janus_network_query_options query_mode, janus_network_query_config *query);
93
103
114const struct ifaddrs *janus_network_query_devices(const struct ifaddrs *ifas, const janus_network_query_config *query);
115
125int janus_network_get_devices_ipv4(const struct ifaddrs *ifa, const janus_network_query_config *query, struct in_addr *result);
126
136int janus_network_get_devices_ipv6(const struct ifaddrs *ifa, const janus_network_query_config *query, struct in6_addr *result);
137
143int janus_network_get_device_address(const struct ifaddrs *ifa, janus_network_address *result);
144
151
159
167
179
186
194
202
210int janus_network_string_is_valid_address(janus_network_query_options addr_type, const char *user_value);
211
220int janus_network_string_to_address(janus_network_query_options addr_type, const char *user_value, janus_network_address *result);
221
229int janus_network_lookup_interface(const struct ifaddrs *ifas, const char *iface, janus_network_address *result);
230
239
249
261int janus_network_resolve_address(const char *host, struct sockaddr_storage *address);
263
264#endif
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 interface description to the given result structure.
Definition ip-utils.c:115
janus_network_query_options
Definition ip-utils.h:27
@ janus_network_query_options_ipv6
Definition ip-utils.h:31
@ janus_network_query_options_ipv4
Definition ip-utils.h:30
@ janus_network_query_options_none
Definition ip-utils.h:28
@ janus_network_query_options_any_ip
Definition ip-utils.h:32
@ janus_network_query_options_name
Definition ip-utils.h:29
@ janus_network_query_options_any
Definition ip-utils.h:33
struct janus_network_query_config janus_network_query_config
Internal object representation of a network device query (configuration).
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 interface description to the given result structure.
Definition ip-utils.c:133
struct janus_network_address_string_buffer janus_network_address_string_buffer
Structure to hold human readable forms of network addresses in a tagged union which should be IPv4 an...
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
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
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
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
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
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
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
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
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
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
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
struct janus_network_address janus_network_address
Structure to hold network addresses in a tagged union which should be IPv4 and IPv6 compatible....
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
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
int janus_network_resolve_address(const char *host, struct sockaddr_storage *address)
Wrapper inet_pton or getaddrinfo to fill a struct sockaddr_storage structure from an address.
Definition ip-utils.c:325
void janus_network_address_nullify(janus_network_address *a)
Set the given network address to a null/nil value.
Definition ip-utils.c:158
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
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
Structure to hold human readable forms of network addresses in a tagged union which should be IPv4 an...
Definition ip-utils.h:71
int family
Definition ip-utils.h:75
char ipv6[INET6_ADDRSTRLEN]
Definition ip-utils.h:78
char ipv4[INET_ADDRSTRLEN]
Definition ip-utils.h:77
Structure to hold network addresses in a tagged union which should be IPv4 and IPv6 compatible....
Definition ip-utils.h:53
struct in_addr ipv4
Definition ip-utils.h:59
struct in6_addr ipv6
Definition ip-utils.h:60
int family
Definition ip-utils.h:57
Internal object representation of a network device query (configuration).
Definition ip-utils.h:39
struct in_addr ipv4
Definition ip-utils.h:42
const char * device_name
Definition ip-utils.h:40
janus_network_query_options mode
Definition ip-utils.h:41
struct in6_addr ipv6
Definition ip-utils.h:43