LCOV - code coverage report
Current view: top level - src/utils - ip_addr.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1422976643 Lines: 16 18 88.9 %
Date: 2015-02-03 Functions: 2 2 100.0 %

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

Generated by: LCOV version 1.10