|
在linux下,用libpcap和libnet包实现:电脑1发包至电脑2,电脑2从第一块网卡(eth0)截包,发到第二块网卡(eth1)上,再由第二块网卡转发指定ip或指定网卡的电脑3上。
内网:电脑1 ip
电脑2 eth0(网络接口)和ip
外网:电脑2 eth1(网络接口) 和ip
电脑3 ip
注:电脑2 eth0的ip 和 eth1的ip是不一样的
库文件:
#ifndef _CAPTURE_H
#define _CAPTURE_H
#include <features.h>
#include <ctype.h>
#include <getopt.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <asm/sockios.h>
#include <net/if.h>
#include <netinet/in.h>
#include <libnet.h>
#define data_packet_len 1514
class CMyCapture
{
public :
CMyCapture();
int SetNetworkType();
void CloseNetworkLink();
int GetSockfd();
int RecvDataFromNetwork(char* device,char *data, int len) ;
int SendDataToNetwork(char* buf, int buf_len, const char* devname);
private :
int recv_sock_fd;
};
#endif
明天就要答辩了。。。真急啊。有好心人请帮个忙,不甚感激。
我QQ510331539
MSN yyhome_hotmail@hotmail.com |
|