资源简介
智能网关部分代码,可作为参考,这是我为公司写的代码,已经运行在各个城市公交地铁wifi上
代码片段和文件信息
#include
#include
#include
#include
#include “string.h“
#include “file.h“
#include “debug.h“
#include “iptables.h“
#define IPTABLES “/usr/sbin/iptables“
#define INPUT_DEV “br-lan“
unsigned char byNetSegment[32] = {‘1‘‘9‘‘2‘‘.‘‘1‘‘6‘‘8‘‘.‘‘1‘0};
static unsigned int i_nat_prerouting_rules_count = 0;
static unsigned int i_filter_input_rules_count= 0;
static void UpdateIptablesPreRulesCount(void);
static inline void UpdateIptablesInputCount(void);
/*
*******************************
* fun:
* arg:
* return:
* time:
* author:
*******************************
*/
void IptablesDeleteRules(unsigned char *table
unsigned char *chain unsigned int number)
{
unsigned char byIptablesCmd[256] = {0};
memset(byIptablesCmd0256);
sprintf(byIptablesCmd“%s -t %s -D %s %d“IPTABLEStablechainnumber);
#if DEBUG_IPTABLES
Trace(“%s\n“byIptablesCmd);
#endif
system(byIptablesCmd);
}
/*
*******************************
* fun:
* arg:
* return:
* time:
* author:
*******************************
*/
inline void IptablesDeleteForwardRules(unsigned int number)
{
IptablesDeleteRules(“filter“ “FORWARD“ number);
}
/*
*******************************
* fun:
* arg:
* return:
* time:
* author:
*******************************
*/
inline void IptablesDeletePreroutingRules(unsigned int number)
{
IptablesDeleteRules(“nat“ “PREROUTING“ number);
}
/*
*******************************
* fun:
* arg:
* return:
* time:
* author:
*******************************
*/
void IptablesDisPartNetAddr(unsigned char *http_addr)
{
unsigned char byIptablesCmd[256] = {0};
memset(byIptablesCmd0256);
sprintf(byIptablesCmd
“%s -t nat -I PREROUTING -p tcp -i %s ! -d %s -j DNAT --to %s“
IPTABLESINPUT_DEVhttp_addrhttp_addr);
#if DEBUG_IPTABLES
Trace(“%s\n“byIptablesCmd);
#endif
system(byIptablesCmd);
UpdateIptablesPreRulesCount();
#if DEBUG_IPTABLES
Trace(“there are [%d] prerouting rules in nat tables by user setup\n“
IptablesGetPreroutRulesCount());
#endif
}
/*
*******************************
* fun:
* arg:
* return:
* time:
* author:
*******************************
*/
void IptablesDisHttpAndJumpSprecifyNetAddr(unsigned char *http_addr)
{
unsigned char byIptablesCmd[256] = {0};
memset(byIptablesCmd0256);
sprintf(byIptablesCmd
“%s -t nat -I PREROUTING -p tcp -i %s --dport 80 -j DNAT --to %s“IPTABLESINPUT_DEVhttp_addr);
#if DEBUG_IPTABLES
Trace(“%s\n“byIptablesCmd);
#endif
system(byIptablesCmd);
UpdateIptablesPreRulesCount();
#if DEBUG_IPTABLES
Trace(“there are [%d] prerouting rules in nat tables by user setup\n“
IptablesGetPreroutRulesCount());
#endif
}
/*
*******************************
* fun:
* arg:
* return:
* time:
* author:
*******************************
*/
void IptablesAllowSprecifyNetAddr(unsigned char *http_addr)
{
unsigned char
- 上一篇:+9V +5V双输出电源原理图PCB图
- 下一篇:opencv 中模板匹配的完整
评论
共有 条评论