資源簡介
智能網關部分代碼,可作為參考,這是我為公司寫的代碼,已經運行在各個城市公交地鐵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 中模板匹配的完整
評論
共有 條評論