summaryrefslogtreecommitdiff
path: root/src/inet.c
diff options
context:
space:
mode:
authorPatrik Flykt <patrik.flykt@linux.intel.com>2012-06-04 10:45:02 (GMT)
committerPatrik Flykt <patrik.flykt@linux.intel.com>2012-06-14 12:05:55 (GMT)
commitb93f2462a3dc6cc00810ed28b87a5c05516c0921 (patch)
tree4c79fa22d5976691536906976272f6e948162d65 /src/inet.c
parent23da213b31cac162597b73438885ca756d11bafd (diff)
downloadconnman-b93f2462a3dc6cc00810ed28b87a5c05516c0921.zip
connman-b93f2462a3dc6cc00810ed28b87a5c05516c0921.tar.gz
connman-b93f2462a3dc6cc00810ed28b87a5c05516c0921.tar.bz2
inet: Create helper function for IP address checking
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.
Diffstat (limited to 'src/inet.c')
-rw-r--r--src/inet.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/inet.c b/src/inet.c
index effa68c..17d58d5 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -2174,6 +2174,26 @@ int __connman_inet_rtnl_addattr32(struct nlmsghdr *n, size_t maxlen, int type,
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)
{