📄 firewallop.c
字号:
#include <dnet.h>
/*
=======================================================================================================================
Libdnet头文件 ;
下面是定义的回调函数,它实现了显示防火墙规则的功能
=======================================================================================================================
*/
int show_firewall_fules(const struct fw_rule *firewall_rule, void *parameter)
{
char operation[100];
/* 操作,表示是禁止还是允许 */
char direction[100];
/* 方向,表示是进入还是出去 */
char net_interface[100];
/* 网络接口 */
char source_ip[100];
/* 源IP地址 */
char destination_ip[100];
/* 目的IP地址 */
char protocol[16];
/* 规则协议类型,在此只分析TCP协议和UDP协议 */
char source_port[16];
/* 源端口号 */
char destination_port[16];
/* 目的端口号 */
static int count = 1;
/* 规则个数 */
operation[0] = '\0';
direction[0] = '\0';
net_interface[0] = '\0';
source_ip[0] = '\0';
destination_ip[0] = '\0';
source_port[0] = '\0';
destination_port[0] = '\0';
if (firewall_rule->fw_proto == 0)
protocol[0] = '\0';
else
{
if (firewall_rule->fw_proto == 6)
/* 表示协议是TCP协议 */
sprintf(protocol, "%s ", "tcp");
if (firewall_rule->fw_proto == 17)
/* 表示协议是UDP协议 */
sprintf(protocol, "%s ", "udp");
}
if (firewall_rule->fw_proto == 6 || firewall_rule->fw_proto == 17)
{
/* 求源端口号 */
if (firewall_rule->fw_sport[0] == firewall_rule->fw_sport[1])
/* 表示端口号只有一个值 */
{
sprintf(source_port, "port = %d", firewall_rule->fw_sport[0]);
}
else
/* 表示端口号是一个范围,例如从1025到65535 */
sprintf(source_port, "port %d-%d", firewall_rule->fw_sport[0], firewall_rule->fw_sport[1]);
/* 求目的端口号 */
if (firewall_rule->fw_dport[0] == firewall_rule->fw_dport[1])
{
sprintf(destination_port, "port = %d", firewall_rule->fw_dport[0]);
}
else
sprintf(destination_port, "port %d-%d", firewall_rule->fw_dport[0], firewall_rule->fw_dport[1]);
}
if (firewall_rule->fw_op == FW_OP_ALLOW)
/* 判断操作类型 */
sprintf(operation, "%s", "pass");
/* 操作类型是允许 */
else
sprintf(operation, "%s", "block");
/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -