diff --git a/cli_classcfg.c b/cli_classcfg.c index df8be8e1e72aed1f88297a5a2e1f1a98e1927770..073db9a42be2cad7bc6912335ac5925628b31b90 100755 --- a/cli_classcfg.c +++ b/cli_classcfg.c @@ -441,22 +441,35 @@ void classcfg_parse_ipaddr_ipmask( const char *optstring, const char* optarg, cl ipmask_conv(subStr[1], &mask); inet_ntop(AF_INET, &(mask), pxipmatch->mask, INET_ADDRSTRLEN); } else { - strncpy_s(pxipmatch->mask, sizeof(pxipmatch->mask), - subStr[1], strnlen_s(subStr[1], QCLI_MAX_STR)); + uint32_t m = -1; + uint32_t prefix = atoi(subStr[1]); + struct in_addr in_mask; + m = m << (32 -prefix); + in_mask.s_addr = htonl(m); + inet_ntop(AF_INET, &(in_mask), pxipmatch->mask, INET_ADDRSTRLEN); } } break; case AF_INET6: - ip6addr_conv(subStr[0], &ipaddr6); - inet_ntop(AF_INET6, &(ipaddr6), pxipmatch->ipaddr, INET_ADDRSTRLEN); + ip6addr_conv(subStr[0], &ipaddr6); + inet_ntop(AF_INET6, &(ipaddr6), pxipmatch->ipaddr, INET6_ADDRSTRLEN); if(nSubCnt == 2) { if (strchr(subStr[1], ':') != NULL) { ip6mask_conv(subStr[1], &mask6); - inet_ntop(AF_INET6, &(mask6), pxipmatch->mask, INET_ADDRSTRLEN); + inet_ntop(AF_INET6, &(mask6), pxipmatch->mask, INET6_ADDRSTRLEN); } else { - strncpy_s(pxipmatch->mask, sizeof(pxipmatch->mask), - subStr[1], strnlen_s(subStr[1], QCLI_MAX_STR)); + struct in6_addr in6 = { 0 }; + uint32_t prefix = atoi(subStr[1]); + int i , j ; + for (i = prefix, j = 0; i > 0; i -= 8, j++) { + if (i >= 8) { + in6.s6_addr[j] = 0xff; + } else { + in6.s6_addr[j] = (unsigned long)(0xffU << (8 - i)); + } + } + inet_ntop(AF_INET6, &(in6), pxipmatch->mask, INET6_ADDRSTRLEN); } } break; @@ -466,6 +479,7 @@ void classcfg_parse_ipaddr_ipmask( const char *optstring, const char* optarg, cl printf("***** Invalid ipaddres/Mask %s passed to %s\n", option_string, optstring); exit(0); } + LOGF_LOG_DEBUG("pxipmatch->ipaddr %s pxipmatch->mask %s\n", pxipmatch->ipaddr, pxipmatch->mask); //freeSubStr(subStr, nSubCnt); }