ip_addr.c
Go to the documentation of this file.
00001 /*
00002  * IP address processing
00003  * Copyright (c) 2003-2006, Jouni Malinen <j@w1.fi>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 2 as
00007  * published by the Free Software Foundation.
00008  *
00009  * Alternatively, this software may be distributed under the terms of BSD
00010  * license.
00011  *
00012  * See README and COPYING for more details.
00013  */
00014 
00015 #include "includes.h"
00016 
00017 #include "common.h"
00018 #include "ip_addr.h"
00019 
00020 const char * hostapd_ip_txt(const struct hostapd_ip_addr *addr, char *buf,
00021                             size_t buflen)
00022 {
00023         if (buflen == 0 || addr == NULL)
00024                 return NULL;
00025 
00026         if (addr->af == AF_INET) {
00027                 os_strlcpy(buf, inet_ntoa(addr->u.v4), buflen);
00028         } else {
00029                 buf[0] = '\0';
00030         }
00031 #ifdef CONFIG_IPV6
00032         if (addr->af == AF_INET6) {
00033                 if (inet_ntop(AF_INET6, &addr->u.v6, buf, buflen) == NULL)
00034                         buf[0] = '\0';
00035         }
00036 #endif /* CONFIG_IPV6 */
00037 
00038         return buf;
00039 }
00040 
00041 
00042 int hostapd_ip_diff(struct hostapd_ip_addr *a, struct hostapd_ip_addr *b)
00043 {
00044         if (a == NULL && b == NULL)
00045                 return 0;
00046         if (a == NULL || b == NULL)
00047                 return 1;
00048 
00049         switch (a->af) {
00050         case AF_INET:
00051                 if (a->u.v4.s_addr != b->u.v4.s_addr)
00052                         return 1;
00053                 break;
00054 #ifdef CONFIG_IPV6
00055         case AF_INET6:
00056                 if (os_memcmp(&a->u.v6, &b->u.v6, sizeof(a->u.v6)) != 0)
00057                         return 1;
00058                 break;
00059 #endif /* CONFIG_IPV6 */
00060         }
00061 
00062         return 0;
00063 }
00064 
00065 
00066 int hostapd_parse_ip_addr(const char *txt, struct hostapd_ip_addr *addr)
00067 {
00068 #ifndef CONFIG_NATIVE_WINDOWS
00069         if (inet_aton(txt, &addr->u.v4)) {
00070                 addr->af = AF_INET;
00071                 return 0;
00072         }
00073 
00074 #ifdef CONFIG_IPV6
00075         if (inet_pton(AF_INET6, txt, &addr->u.v6) > 0) {
00076                 addr->af = AF_INET6;
00077                 return 0;
00078         }
00079 #endif /* CONFIG_IPV6 */
00080 #endif /* CONFIG_NATIVE_WINDOWS */
00081 
00082         return -1;
00083 }


wpa_supplicant
Author(s): Package maintained by Blaise Gassend
autogenerated on Thu Apr 24 2014 15:34:35