hostapd: Update vendor branch to 0.6.10
[dragonfly.git] / contrib / hostapd / src / utils / ip_addr.c
blob158fd57ed01700238e06fcf1f3765fa957a4beaa
1 /*
2 * IP address processing
3 * Copyright (c) 2003-2006, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
10 * license.
12 * See README and COPYING for more details.
15 #include "includes.h"
17 #include "common.h"
18 #include "ip_addr.h"
20 const char * hostapd_ip_txt(const struct hostapd_ip_addr *addr, char *buf,
21 size_t buflen)
23 if (buflen == 0 || addr == NULL)
24 return NULL;
26 if (addr->af == AF_INET) {
27 os_strlcpy(buf, inet_ntoa(addr->u.v4), buflen);
28 } else {
29 buf[0] = '\0';
31 #ifdef CONFIG_IPV6
32 if (addr->af == AF_INET6) {
33 if (inet_ntop(AF_INET6, &addr->u.v6, buf, buflen) == NULL)
34 buf[0] = '\0';
36 #endif /* CONFIG_IPV6 */
38 return buf;
42 int hostapd_ip_diff(struct hostapd_ip_addr *a, struct hostapd_ip_addr *b)
44 if (a == NULL && b == NULL)
45 return 0;
46 if (a == NULL || b == NULL)
47 return 1;
49 switch (a->af) {
50 case AF_INET:
51 if (a->u.v4.s_addr != b->u.v4.s_addr)
52 return 1;
53 break;
54 #ifdef CONFIG_IPV6
55 case AF_INET6:
56 if (os_memcmp(&a->u.v6, &b->u.v6, sizeof(a->u.v6)) != 0)
57 return 1;
58 break;
59 #endif /* CONFIG_IPV6 */
62 return 0;
66 int hostapd_parse_ip_addr(const char *txt, struct hostapd_ip_addr *addr)
68 #ifndef CONFIG_NATIVE_WINDOWS
69 if (inet_aton(txt, &addr->u.v4)) {
70 addr->af = AF_INET;
71 return 0;
74 #ifdef CONFIG_IPV6
75 if (inet_pton(AF_INET6, txt, &addr->u.v6) > 0) {
76 addr->af = AF_INET6;
77 return 0;
79 #endif /* CONFIG_IPV6 */
80 #endif /* CONFIG_NATIVE_WINDOWS */
82 return -1;