Create a helper function that checks if a given hostname is an IPv4
or IPv6 address. If it is, AF_INET or AF_INET6 is returned. On
error the negative error value from getaddrinfo is returned.
int connman_inet_create_tunnel(char **iface);
int connman_inet_get_dest_addr(int index, char **dest);
int connman_inet_ipv6_get_dest_addr(int index, char **dest);
+int connman_inet_check_ipaddress(const char *host);
connman_bool_t connman_inet_check_hostname(const char *ptr, size_t len);
#ifdef __cplusplus
return 0;
}
+int connman_inet_check_ipaddress(const char *host)
+{
+ struct addrinfo hints;
+ struct addrinfo *addr;
+ int result;
+
+ memset(&hints, 0, sizeof(struct addrinfo));
+ hints.ai_flags = AI_NUMERICHOST;
+ addr = NULL;
+
+ result = getaddrinfo(host, NULL, &hints, &addr);
+ if (result == 0)
+ result = addr->ai_family;
+ else
+ result = -result;
+ freeaddrinfo(addr);
+
+ return result;
+}
+
/* Check routine modified from ics-dhcp 4.2.3-P2 */
connman_bool_t connman_inet_check_hostname(const char *ptr, size_t len)
{