ip_addr.c

Go to the documentation of this file.
00001 
00016 #include "includes.h"
00017 
00018 #include "common.h"
00019 #include "ip_addr.h"
00020 
00021 const char * hostapd_ip_txt(const struct hostapd_ip_addr *addr, char *buf,
00022                             size_t buflen)
00023 {
00024         if (buflen == 0 || addr == NULL)
00025                 return NULL;
00026 
00027         if (addr->af == AF_INET) {
00028                 os_strlcpy(buf, inet_ntoa(addr->u.v4), buflen);
00029         } else {
00030                 buf[0] = '\0';
00031         }
00032 #ifdef CONFIG_IPV6
00033         if (addr->af == AF_INET6) {
00034                 if (inet_ntop(AF_INET6, &addr->u.v6, buf, buflen) == NULL)
00035                         buf[0] = '\0';
00036         }
00037 #endif /* CONFIG_IPV6 */
00038 
00039         return buf;
00040 }
00041 
00042 
00043 int hostapd_ip_diff(struct hostapd_ip_addr *a, struct hostapd_ip_addr *b)
00044 {
00045         if (a == NULL && b == NULL)
00046                 return 0;
00047         if (a == NULL || b == NULL)
00048                 return 1;
00049 
00050         switch (a->af) {
00051         case AF_INET:
00052                 if (a->u.v4.s_addr != b->u.v4.s_addr)
00053                         return 1;
00054                 break;
00055 #ifdef CONFIG_IPV6
00056         case AF_INET6:
00057                 if (os_memcmp(&a->u.v6, &b->u.v6, sizeof(a->u.v6)) != 0)
00058                         return 1;
00059                 break;
00060 #endif /* CONFIG_IPV6 */
00061         }
00062 
00063         return 0;
00064 }
00065 
00066 
00067 int hostapd_parse_ip_addr(const char *txt, struct hostapd_ip_addr *addr)
00068 {
00069 #ifndef CONFIG_NATIVE_WINDOWS
00070         if (inet_aton(txt, &addr->u.v4)) {
00071                 addr->af = AF_INET;
00072                 return 0;
00073         }
00074 
00075 #ifdef CONFIG_IPV6
00076         if (inet_pton(AF_INET6, txt, &addr->u.v6) > 0) {
00077                 addr->af = AF_INET6;
00078                 return 0;
00079         }
00080 #endif /* CONFIG_IPV6 */
00081 #endif /* CONFIG_NATIVE_WINDOWS */
00082 
00083         return -1;
00084 }
00085 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on Sat Nov 21 23:16:54 2009 for hostapd by  doxygen 1.6.1