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 1393793999 Lines: 16 31 51.6 %
Date: 2014-03-02 Functions: 2 3 66.7 %
Branches: 10 29 34.5 %

           Branch data     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                 :        156 : const char * hostapd_ip_txt(const struct hostapd_ip_addr *addr, char *buf,
      15                 :            :                             size_t buflen)
      16                 :            : {
      17 [ +  - ][ -  + ]:        156 :         if (buflen == 0 || addr == NULL)
      18                 :          0 :                 return NULL;
      19                 :            : 
      20         [ +  + ]:        156 :         if (addr->af == AF_INET) {
      21                 :        154 :                 os_strlcpy(buf, inet_ntoa(addr->u.v4), buflen);
      22                 :            :         } else {
      23                 :          2 :                 buf[0] = '\0';
      24                 :            :         }
      25                 :            : #ifdef CONFIG_IPV6
      26         [ +  + ]:        156 :         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                 :        156 :         return buf;
      33                 :            : }
      34                 :            : 
      35                 :            : 
      36                 :          0 : int hostapd_ip_diff(struct hostapd_ip_addr *a, struct hostapd_ip_addr *b)
      37                 :            : {
      38 [ #  # ][ #  # ]:          0 :         if (a == NULL && b == NULL)
      39                 :          0 :                 return 0;
      40 [ #  # ][ #  # ]:          0 :         if (a == NULL || b == NULL)
      41                 :          0 :                 return 1;
      42                 :            : 
      43      [ #  #  # ]:          0 :         switch (a->af) {
      44                 :            :         case AF_INET:
      45         [ #  # ]:          0 :                 if (a->u.v4.s_addr != b->u.v4.s_addr)
      46                 :          0 :                         return 1;
      47                 :          0 :                 break;
      48                 :            : #ifdef CONFIG_IPV6
      49                 :            :         case AF_INET6:
      50         [ #  # ]:          0 :                 if (os_memcmp(&a->u.v6, &b->u.v6, sizeof(a->u.v6)) != 0)
      51                 :          0 :                         return 1;
      52                 :          0 :                 break;
      53                 :            : #endif /* CONFIG_IPV6 */
      54                 :            :         }
      55                 :            : 
      56                 :          0 :         return 0;
      57                 :            : }
      58                 :            : 
      59                 :            : 
      60                 :        203 : int hostapd_parse_ip_addr(const char *txt, struct hostapd_ip_addr *addr)
      61                 :            : {
      62                 :            : #ifndef CONFIG_NATIVE_WINDOWS
      63         [ +  + ]:        203 :         if (inet_aton(txt, &addr->u.v4)) {
      64                 :        200 :                 addr->af = AF_INET;
      65                 :        200 :                 return 0;
      66                 :            :         }
      67                 :            : 
      68                 :            : #ifdef CONFIG_IPV6
      69         [ +  - ]:          3 :         if (inet_pton(AF_INET6, txt, &addr->u.v6) > 0) {
      70                 :          3 :                 addr->af = AF_INET6;
      71                 :          3 :                 return 0;
      72                 :            :         }
      73                 :            : #endif /* CONFIG_IPV6 */
      74                 :            : #endif /* CONFIG_NATIVE_WINDOWS */
      75                 :            : 
      76                 :        203 :         return -1;
      77                 :            : }

Generated by: LCOV version 1.9