1e5b75505Sopenharmony_ci/* 2e5b75505Sopenharmony_ci * IP address processing 3e5b75505Sopenharmony_ci * Copyright (c) 2003-2006, Jouni Malinen <j@w1.fi> 4e5b75505Sopenharmony_ci * 5e5b75505Sopenharmony_ci * This software may be distributed under the terms of the BSD license. 6e5b75505Sopenharmony_ci * See README for more details. 7e5b75505Sopenharmony_ci */ 8e5b75505Sopenharmony_ci 9e5b75505Sopenharmony_ci#include "includes.h" 10e5b75505Sopenharmony_ci 11e5b75505Sopenharmony_ci#include "common.h" 12e5b75505Sopenharmony_ci#include "ip_addr.h" 13e5b75505Sopenharmony_ci 14e5b75505Sopenharmony_ciconst char * hostapd_ip_txt(const struct hostapd_ip_addr *addr, char *buf, 15e5b75505Sopenharmony_ci size_t buflen) 16e5b75505Sopenharmony_ci{ 17e5b75505Sopenharmony_ci if (buflen == 0 || addr == NULL) 18e5b75505Sopenharmony_ci return NULL; 19e5b75505Sopenharmony_ci 20e5b75505Sopenharmony_ci if (addr->af == AF_INET) { 21e5b75505Sopenharmony_ci os_strlcpy(buf, inet_ntoa(addr->u.v4), buflen); 22e5b75505Sopenharmony_ci } else { 23e5b75505Sopenharmony_ci buf[0] = '\0'; 24e5b75505Sopenharmony_ci } 25e5b75505Sopenharmony_ci#ifdef CONFIG_IPV6 26e5b75505Sopenharmony_ci if (addr->af == AF_INET6) { 27e5b75505Sopenharmony_ci if (inet_ntop(AF_INET6, &addr->u.v6, buf, buflen) == NULL) 28e5b75505Sopenharmony_ci buf[0] = '\0'; 29e5b75505Sopenharmony_ci } 30e5b75505Sopenharmony_ci#endif /* CONFIG_IPV6 */ 31e5b75505Sopenharmony_ci 32e5b75505Sopenharmony_ci return buf; 33e5b75505Sopenharmony_ci} 34e5b75505Sopenharmony_ci 35e5b75505Sopenharmony_ci 36e5b75505Sopenharmony_ciint hostapd_parse_ip_addr(const char *txt, struct hostapd_ip_addr *addr) 37e5b75505Sopenharmony_ci{ 38e5b75505Sopenharmony_ci#ifndef CONFIG_NATIVE_WINDOWS 39e5b75505Sopenharmony_ci if (inet_aton(txt, &addr->u.v4)) { 40e5b75505Sopenharmony_ci addr->af = AF_INET; 41e5b75505Sopenharmony_ci return 0; 42e5b75505Sopenharmony_ci } 43e5b75505Sopenharmony_ci 44e5b75505Sopenharmony_ci#ifdef CONFIG_IPV6 45e5b75505Sopenharmony_ci if (inet_pton(AF_INET6, txt, &addr->u.v6) > 0) { 46e5b75505Sopenharmony_ci addr->af = AF_INET6; 47e5b75505Sopenharmony_ci return 0; 48e5b75505Sopenharmony_ci } 49e5b75505Sopenharmony_ci#endif /* CONFIG_IPV6 */ 50e5b75505Sopenharmony_ci#endif /* CONFIG_NATIVE_WINDOWS */ 51e5b75505Sopenharmony_ci 52e5b75505Sopenharmony_ci return -1; 53e5b75505Sopenharmony_ci} 54