📄 divertsocket.hh
字号:
#ifndef DIVERTSOCKET_HH#define DIVERTSOCKET_HH/*=title DivertSocket=cDivertSocket(DEVICE, DIVERTPORT, FWRULENUM, PROTOCOL, SADDR/MASK, SPORT, DADDR/MASK, DPORT, [DIRECTION])DivertSocket(DIVERTPORT)=s sources=d DivertSocket sets up a firewall rule according to the input parameters, and diverts matching IP packets to it's output port.DIRECTION can be either "in" or "out" for packets coming into this machineor going out of this machine.If the only argument is DIVERTPORT, then the firewall is not changed. Insteadthe DivertSocket simply channels packets from packets diverted to DIVERTPORT.In this case, the administrator must manually insert firewall rules to use theDivertSocket.*/#include <click/element.hh>#if defined(__linux__)# include <getopt.h># include <netdb.h># include <netinet/in.h># include <sys/types.h># include <linux/types.h># include <signal.h># include <netinet/ip.h># include <netinet/tcp.h># include <netinet/udp.h># include <net/if.h># include <sys/param.h># include <linux/types.h># include <linux/icmp.h># include <linux/ip_fw.h># define IPPROTO_DIVERT 254#endifclass DivertSocket : public Element {public: DivertSocket(); ~DivertSocket(); const char *class_name() const { return "DivertSocket"; } const char *processing() const { return PUSH;} void notify_ninputs(int n); void notify_noutputs(int n); int configure(const Vector<String> &, ErrorHandler *); int initialize(ErrorHandler *errh); void uninitialize(); void selected(int fd); void push(int, Packet *p);private: bool _setup_fw; bool _have_sport; bool _have_dport; int _fd; unsigned char _protocol; IPAddress _saddr, _smask, _daddr, _dmask; int32_t _sportl, _sporth, _dportl, _dporth, _divertport, _rulenumber; String _device, _inout;#ifdef __linux__ struct ip_fw fw, fw2; struct ip_fwuser ipfu, ipfu2; struct ip_fwnew ipfc, ipfc2; int fw_sock;#endif int setup_firewall(ErrorHandler *errh); int parse_ports(const String ¶m, ErrorHandler *errh, int32_t *sportl, int32_t *sporth); void send_packet(Packet *p); };#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -