aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/ip_addr.c
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2008-02-28 01:34:43 (GMT)
committerJouni Malinen <jm@jm.kir.nu>2008-02-28 01:34:43 (GMT)
commit6fc6879bd55a394f807cbbe927df736c190cb8ab (patch)
treecdf50da0c58f21510a808d53502a060d911ff243 /src/utils/ip_addr.c
downloadhostap-6fc6879bd55a394f807cbbe927df736c190cb8ab.zip
hostap-6fc6879bd55a394f807cbbe927df736c190cb8ab.tar.gz
hostap-6fc6879bd55a394f807cbbe927df736c190cb8ab.tar.bz2
Re-initialize hostapd/wpa_supplicant git repository based on 0.6.3 release
Diffstat (limited to 'src/utils/ip_addr.c')
-rw-r--r--src/utils/ip_addr.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/utils/ip_addr.c b/src/utils/ip_addr.c
new file mode 100644
index 0000000..d40a871
--- /dev/null
+++ b/src/utils/ip_addr.c
@@ -0,0 +1,84 @@
+/*
+ * IP address processing
+ * Copyright (c) 2003-2006, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "ip_addr.h"
+
+const char * hostapd_ip_txt(const struct hostapd_ip_addr *addr, char *buf,
+ size_t buflen)
+{
+ if (buflen == 0 || addr == NULL)
+ return NULL;
+
+ if (addr->af == AF_INET) {
+ os_strlcpy(buf, inet_ntoa(addr->u.v4), buflen);
+ } else {
+ buf[0] = '\0';
+ }
+#ifdef CONFIG_IPV6
+ if (addr->af == AF_INET6) {
+ if (inet_ntop(AF_INET6, &addr->u.v6, buf, buflen) == NULL)
+ buf[0] = '\0';
+ }
+#endif /* CONFIG_IPV6 */
+
+ return buf;
+}
+
+
+int hostapd_ip_diff(struct hostapd_ip_addr *a, struct hostapd_ip_addr *b)
+{
+ if (a == NULL && b == NULL)
+ return 0;
+ if (a == NULL || b == NULL)
+ return 1;
+
+ switch (a->af) {
+ case AF_INET:
+ if (a->u.v4.s_addr != b->u.v4.s_addr)
+ return 1;
+ break;
+#ifdef CONFIG_IPV6
+ case AF_INET6:
+ if (os_memcpy(&a->u.v6, &b->u.v6, sizeof(a->u.v6))
+ != 0)
+ return 1;
+ break;
+#endif /* CONFIG_IPV6 */
+ }
+
+ return 0;
+}
+
+
+int hostapd_parse_ip_addr(const char *txt, struct hostapd_ip_addr *addr)
+{
+#ifndef CONFIG_NATIVE_WINDOWS
+ if (inet_aton(txt, &addr->u.v4)) {
+ addr->af = AF_INET;
+ return 0;
+ }
+
+#ifdef CONFIG_IPV6
+ if (inet_pton(AF_INET6, txt, &addr->u.v6) > 0) {
+ addr->af = AF_INET6;
+ return 0;
+ }
+#endif /* CONFIG_IPV6 */
+#endif /* CONFIG_NATIVE_WINDOWS */
+
+ return -1;
+}