Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / wpa / src / utils / ip_addr.c
blobd40a8712efe5c469a8203622a3e0ed728e4b75dc
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_memcpy(&a->u.v6, &b->u.v6, sizeof(a->u.v6))
57 != 0)
58 return 1;
59 break;
60 #endif /* CONFIG_IPV6 */
63 return 0;
67 int hostapd_parse_ip_addr(const char *txt, struct hostapd_ip_addr *addr)
69 #ifndef CONFIG_NATIVE_WINDOWS
70 if (inet_aton(txt, &addr->u.v4)) {
71 addr->af = AF_INET;
72 return 0;
75 #ifdef CONFIG_IPV6
76 if (inet_pton(AF_INET6, txt, &addr->u.v6) > 0) {
77 addr->af = AF_INET6;
78 return 0;
80 #endif /* CONFIG_IPV6 */
81 #endif /* CONFIG_NATIVE_WINDOWS */
83 return -1;