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

/* 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;
                    }