码迷,mamicode.com
首页 > 编程语言 > 详细

C语言中字符串数组的遍历和比较

时间:2015-05-22 14:44:06      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:

/* The list of known types of default packet. */
static char  *_default_packet_types[] = {
    "ddos client quota",       "ddos server quota",
    "blocked ports",           "blocked sites",
    "ip scan",                 "port scan",
    "ip source route",         "icmp flooding",
    "ike flooding",            "ipsec flooding",
    "ip spoofing sites",       "syn flooding",
    "udp flooding",            "tcp syn checking failed",
    NULL
};

 

// 自己写的函数,用packetTable中的->_msg, 和上面的_default_packet_types里的元素进行比较,如果相等则跳出,否则继续循环

boolean pr_get_default_packet_flag_from_msg(PacketFilterMessageTable *packetTable, char **packetType)
{
    char         *p_msg = NULL;
    wgpr_boolean  flag = FALSE;
    char        **type_ptr = NULL;
   
    /* Sanity check */
    if (!packetTable) {
        return flag;
    }

    if (packetTable->_tag_id != FWDENY_TAG ||
        packetTable->_msg == NULL          ||
        packetTable->_msg[0] == ‘\0‘) {
        return flag;
    }

    p_msg = packetTable->_msg;

    for (type_ptr = _default_packet_types; *type_ptr != NULL; type_ptr++) {
        if (!strncasecmp(p_msg, *type_ptr, sizeof(*type_ptr) - 1)) {
            flag = TRUE;
            break;
        }
    }
    *packetType = flag == TRUE ? DEFAULTPACKET : DENIEDPACKET;
    return flag;
}

 

//调用上述函数的代码片段

                    if(pr_get_default_packet_flag_from_msg(pk_t, &packetType)){
                        is_dflt_packet = TRUE;
                    }

 

C语言中字符串数组的遍历和比较

标签:

原文地址:http://www.cnblogs.com/kungfupanda/p/4341212.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!