資源簡介
linux下使用原始套接字抓包并發現網絡網元,構造數據包,實現過濾規則與數據包統計

代碼片段和文件信息
#include?
#include?
#include?
#include?
#include??
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#define?MAX_frame_LEN?1500
typedef?struct?option
{
int?ethernet_flag;
int?arp_flag;
int?ip_flag;
int?icmp_flag;
int?tcp_flag;
int?udp_flag;
int?dump_flag;
int?aflag;
int?f_flag;
}opt;
typedef?struct?dataid
{
char?s_time[50];
char?e_time[50];
int?total_packet;
int?ip_packet;
int?udp_packet;
int?tcp_packet;
int?icmp_packet;
int?arp_packet;
int?mac_broad;
int?mac_short;
int?mac_long;
int?byte;
int?redirect;
int?unreach;
}did;
did?num;
void?inital_opt(opt*?node);
void?inital_did(did*?node);
char*?mac_ntoa(char*?mac_buf);
char*?tcp_ftoa(struct?tcphdr*?ptcp);
int?is_exist(FILE*?fpchar*?s);
void?sig_handle(int?sig);
void?info_file();
struct?iphdr*?fill_iphead(const?char?*src_ip?const?char?*dst_ip?int?ip_packet_len);
struct?tcphdr*?fill_tcphead(int?src_portint?dst_port);
void?make_packet(const?char?*src_ip?int?src_port?const?char?*dst_ip?int?dst_port?const?char?*data);
int?catch_packet(char*?stropt*?nodechar*?filtersint?portchar*?ip);
void?print_ethernet(struct?ether_header*?peth);
void?do_ip(char*?dataopt*?node);
void?print_ip(struct?iphdr*?pip);
void?do_arp(char*?dataopt*?node);
void?print_arp(struct?arphdr*?parp);
void?do_icmp(char*?dataopt*?node);
void?print_icmp(struct?icmphdr*?picmp);
void?do_udp(char*?dataopt*?node);
void?print_udp(struct?udphdr*?pudp);
void?do_tcp(char*?dataopt*?node);
void?print_tcp(struct?tcphdr*?ptcp);
void?Dump_packet(unsigned?char*?bufint?len);
void?inital_did(did*?node)
{
node->total_packet=0;
node->ip_packet=0;
node->udp_packet=0;
node->tcp_packet=0;
node->icmp_packet=0;
node->arp_packet=0;
node->mac_broad=0;
node->mac_short=0;
node->mac_long=0;
node->byte=0;
node->redirect=0;
node->unreach=0;
}
void?inital_opt(opt*?node)
{
node->ethernet_flag=0;
node->arp_flag=1;
node->ip_flag=1;
node->icmp_flag=0;
node->tcp_flag=0;
node->udp_flag=0;
node->dump_flag=0;
node->aflag=0;
node->f_flag=0;
}
char*?mac_ntoa(char*?mac_buf)
{
static?char?buf[18];
sprintf(buf?“%02x:%02x:%02x:%02x:%02x:%02x\n“?(unsigned?char)*mac_buf?
????????????(unsigned?char)(*(mac_buf?+?1))?(unsigned?char)(*(mac_buf?+?2))?
????????????(unsigned?char)*(mac_buf?+?3)?(unsigned?char)(*(mac_buf?+?4))?
????????????(unsigned?char)*(mac_buf?+?5));
buf[17]=0;
return?buf;
}
char*?tcp_ftoa(struct?tcphdr*?ptcp)
{
static?char?flag[9]={‘0‘‘0‘‘0‘‘0‘‘0‘‘0‘‘0‘‘0‘};
if(ntohs(ptcp->ece)!=0)
{
flag[0]=‘e‘;
}
if(ntohs(ptcp->cwr)!=0)
{
flag[1]=‘c‘;
}
if(ntohs(ptcp->urg)!=0)
{
flag[2]=‘u‘;
}
if(ntohs(ptcp->ack)!=0)
{
flag[3]=‘a‘;
}
if(ntohs(ptcp->psh)!
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????23696??2018-12-03?14:22??ipdump_complex.c
- 上一篇:SSD1306 oled 驅動代碼
- 下一篇:杭電考博復習矩陣理論試題A.doc
評論
共有 條評論