The traversal and comparison of string arrays in C Language
/* 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
};
// For a self-written function, use-> _ msg in packetTable to compare it with the elements in _ default_packet_types above. If the values are the same, the function jumps out. Otherwise, the loop continues.
Boolean pr_get_default_packet_flag_from_msg (PacketFilterMessageTable * packetTable, char ** packetType)
{
Char * p_msg = NULL;
Wupl_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;
}
// Code snippet for calling the above function
If (pr_get_default_packet_flag_from_msg (pk_t, & packetType )){
Is_dflt_packet = TRUE;
}