<commit_before>/*
 <NAME>
 Cisco Systems, Inc.
*/

/*
Copyright (c) 2015-2016 Cisco Systems, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include <istream>
#include <fstream>
#include "common/basic_utils.h"
#include <common/Network/Packet/CPktCmn.h>
#include "utl_yaml.h"

#define INADDRSZ 4

extern int my_inet_pton4(const char *src, unsigned char *dst);
extern int my_inet_pton6(const char *src, unsigned char *dst);

bool utl_yaml_read_ip_addr(const YAML::Node& node,
                           const std::string &name,
                           uint32_t & val){
    std::string tmp;
    uint32_t ip;
    bool res=false;
    if ( node.FindValue(name) ) {
        node[name] >> tmp ;
        if ( my_inet_pton4((char *)tmp.c_str(), (unsigned char *)&ip) ){
            val=PKT_NTOHL(ip);
            res=true;
        }else{
            printf(" Error: non valid ip %s \n",(char *)tmp.c_str());
            exit(1);
        }
    }
    return (res);
}

bool utl_yaml_read_uint32(const YAML::Node& node,
                          const std::string &name,
                          uint32_t & val){
    bool res=false;
    if ( node.FindValue(name) ) {
        node[name] >> val ;
        res=true;
    }
    return (res);
}

bool utl_yaml_read_uint16(const YAML::Node& node,
                          const std::string &name,
                          uint16_t & val, uint16_t min, uint16_t max) {
    bool res = utl_yaml_read_uint16(node, name, val);

    if ((val < min) || (val > max)) {
        fprintf(stderr
                , "Parsing error: value of field '%s' must be between %d and %d\n"
                , name.c_str(), min, max);
        exit(1);
    }

    return res;
}

bool utl_yaml_read_uint16(const YAML::Node& node,
                          const std::string &name,
                          uint16_t & val){
    uint32_t val_tmp;
    bool res=false;
    if ( node.FindValue(name) ) {
        node[name] >> val_tmp ;
        val = (uint16_t)val_tmp;
        res=true;
    }
<commit_msg>Small fix to vlan range check<commit_after>/*
 <NAME>
 Cisco Systems, Inc.
*/

/*
Copyright (c) 2015-2016 Cisco Systems, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include <istream>
#include <fstream>
#include "common/basic_utils.h"
#include <common/Network/Packet/CPktCmn.h>
#include "utl_yaml.h"

#define INADDRSZ 4

extern int my_inet_pton4(const char *src, unsigned char *dst);
extern int my_inet_pton6(const char *src, unsigned char *dst);

bool utl_yaml_read_ip_addr(const YAML::Node& node,
                           const std::string &name,
                           uint32_t & val){
    std::string tmp;
    uint32_t ip;
    bool res=false;
    if ( node.FindValue(name) ) {
        node[name] >> tmp ;
        if ( my_inet_pton4((char *)tmp.c_str(), (unsigned char *)&ip) ){
            val=PKT_NTOHL(ip);
            res=true;
        }else{
            printf(" Error: non valid ip %s \n",(char *)tmp.c_str());
            exit(1);
        }
    }
    return (res);
}

bool utl_yaml_read_uint32(const YAML::Node& node,
                          const std::string &name,
                          uint32_t & val){
    bool res=false;
    if ( node.FindValue(name) ) {
        node[name] >> val ;
        res=true;
    }
    return (res);
}

bool utl_yaml_read_uint16(const YAML::Node& node,
                          const std::string &name,
                          uint16_t & val, uint16_t min, uint16_t max) {
    bool res = utl_yaml_read_uint16(node, name, val);

    if (res) {
        if ((val < min) || (val > max)) {
            fprintf(stderr
                    , "Parsing error: value of field '%s' must be between %d and %d\n"
                    , name.c_str(), min, max);
            exit(1);
        }
    }

    return res;
}

bool utl_yaml_read_uint16(const YAML::Node& node,
                          const std::string &name,
                          uint16_t & val){
    uint32_t val_tmp;
    bool res=false;
    if ( node.FindValue(name) ) {
        node[name] >> val_tmp ;
        val = (uint16_t)val_tmp;
        res=true;
    }

{'fraction_non_alphanumeric': 0.11042944785276074, 'fraction_numerical': 0.01741539679398377, 'mean_word_length': 2.150872817955112, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1628965', 'n_tokens_mistral': 1667, 'n_tokens_neox': 1594, 'n_words': 481}