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 1443382998 Lines: 18 18 100.0 %
Date: 2015-09-27 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         505 : const char * hostapd_ip_txt(const struct hostapd_ip_addr *addr, char *buf,
      15             :                             size_t buflen)
      16             : {
      17         505 :         if (buflen == 0 || addr == NULL)
      18           2 :                 return NULL;
      19             : 
      20         503 :         if (addr->af == AF_INET) {
      21         498 :                 os_strlcpy(buf, inet_ntoa(addr->u.v4), buflen);
      22             :         } else {
      23           5 :                 buf[0] = '\0';
      24             :         }
      25             : #ifdef CONFIG_IPV6
      26         503 :         if (addr->af == AF_INET6) {
      27           4 :                 if (inet_ntop(AF_INET6, &addr->u.v6, buf, buflen) == NULL)
      28           1 :                         buf[0] = '\0';
      29             :         }
      30             : #endif /* CONFIG_IPV6 */
      31             : 
      32         503 :         return buf;
      33             : }
      34             : 
      35             : 
      36         554 : int hostapd_parse_ip_addr(const char *txt, struct hostapd_ip_addr *addr)
      37             : {
      38             : #ifndef CONFIG_NATIVE_WINDOWS
      39         554 :         if (inet_aton(txt, &addr->u.v4)) {
      40         545 :                 addr->af = AF_INET;
      41         545 :                 return 0;
      42             :         }
      43             : 
      44             : #ifdef CONFIG_IPV6
      45           9 :         if (inet_pton(AF_INET6, txt, &addr->u.v6) > 0) {
      46           5 :                 addr->af = AF_INET6;
      47           5 :                 return 0;
      48             :         }
      49             : #endif /* CONFIG_IPV6 */
      50             : #endif /* CONFIG_NATIVE_WINDOWS */
      51             : 
      52           4 :         return -1;
      53             : }

Generated by: LCOV version 1.10