Fork me on GitHub
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 
25 typedef enum janus_ip_network_query_options {
34 
39  const char * device_name;
41  struct in_addr ipv4;
42  struct in6_addr ipv6;
44 
52 typedef struct janus_network_address {
56  int family;
57  union {
58  struct in_addr ipv4;
59  struct in6_addr ipv6;
60  };
62 
74  int family;
75  union {
76  char ipv4[INET_ADDRSTRLEN];
77  char ipv6[INET6_ADDRSTRLEN];
78  };
80 
91 int janus_prepare_network_device_query(const char *user_value, const janus_ip_network_query_options query_mode, janus_network_query_config *query);
92 
102 
113 const struct ifaddrs * janus_query_network_devices(const struct ifaddrs *ifas, const janus_network_query_config *query);
114 
123 int janus_get_network_devices_ipv4(const struct ifaddrs *ifa, const janus_network_query_config *query, struct in_addr *result);
124 
133 int janus_get_network_devices_ipv6(const struct ifaddrs *ifa, const janus_network_query_config *query, struct in6_addr *result);
134 
140 int janus_get_network_device_address(const struct ifaddrs *ifa, janus_network_address *result);
141 
148 
156 
168 
175 
183 
192 
193 #endif
Definition: ip-utils.h:29
int family
Definition: ip-utils.h:74
janus_ip_network_query_options mode
Definition: ip-utils.h:40
Definition: ip-utils.h:28
const char * device_name
Definition: ip-utils.h:39
struct janus_network_address janus_network_address
Structure to hold network addresses in a tagged union which should be IPv4 and IPv6 compatible...
void janus_network_address_nullify(janus_network_address *a)
Set the given network address to a null/nil value.
Definition: ip-utils.c:158
Definition: ip-utils.h:30
janus_ip_network_query_options
Definition: ip-utils.h:26
struct in_addr ipv4
Definition: ip-utils.h:41
int janus_prepare_network_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:103
const struct ifaddrs * janus_query_network_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.
Definition: ip-utils.c:69
Internal object representation of a network device query (configuration).
Definition: ip-utils.h:38
int janus_get_network_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:112
Definition: ip-utils.h:32
int janus_get_network_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:131
int janus_prepare_network_device_query(const char *user_value, const janus_ip_network_query_options query_mode, janus_network_query_config *query)
Initialise a network device query.
Definition: ip-utils.c:79
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:169
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:183
Definition: ip-utils.h:27
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:190
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...
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:194
Definition: ip-utils.h:31
Structure to hold network addresses in a tagged union which should be IPv4 and IPv6 compatible...
Definition: ip-utils.h:52
struct in6_addr ipv6
Definition: ip-utils.h:42
int family
Definition: ip-utils.h:56
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
struct janus_network_query_config janus_network_query_config
Internal object representation of a network device query (configuration).
Structure to hold human readable forms of network addresses in a tagged union which should be IPv4 an...
Definition: ip-utils.h:70
int janus_get_network_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:140