資源簡介
簡單的網絡嗅探器

代碼片段和文件信息
/*
?*?arp.c
?*
?*??Created?on:?2009-7-7
?*??????Author:?lele
?*
?*??????處理ARP請求
?*??????Hardware?type? Protocol?type
Hardware?address?length? Protocol?address?length? Opcode
Source?hardware?address?:::
Source?protocol?address?:::
Destination?hardware?address?:::
Destination?protocol?address?:::
Data?:::
?*
?*/
#include?“sniffer.h“
void?handle_arp?(const?u_char*?packet)
{
//ARP?頭
struct?nast_arp_hdr?*arp;
struct?libnet_ethernet_hdr?*eptr;
u_short?ether_type;
eptr?=?(struct?libnet_ethernet_hdr?*)?packet;
arp?=?(struct?nast_arp_hdr?*)?(packet+offset);
ether_type?=?ntohs(eptr->ether_type);
if?(ether_type?==?ETHERTYPE_ARP)
{
fprintf(logfile?“\n---[?ARP?]-----------------------------------------------------------\n“);
fprintf(logfile?“%s?->?“?nast_hex_ntoa?(eptr->ether_shost));
fprintf(logfile?“%s\n“?nast_hex_ntoa?(eptr->ether_dhost));
switch?(ntohs(arp->ar_op))
??{
???case?1:
???????{
??fprintf(logfile?“類型:?ARP?請求:?“);
??fprintf(logfile?“Who?has?%d.%d.%d.%d??“arp->__ar_tip[0]arp->__ar_tip[1]arp->__ar_tip[2]arp->__ar_tip[3]);
??fprintf(logfile?“Tell?%d.%d.%d.%d\n“arp->__ar_sip[0]arp->__ar_sip[1]arp->__ar_sip[2]arp->__ar_sip[3]);
???????}
?????break;
???case?2:
???????{
??fprintf(logfile?“類型:?ARP?應答:?“);
??fprintf(logfile?“%d.%d.%d.%d?is?at?%s\n“arp->__ar_sip[0]arp->__ar_sip[1]arp->__ar_sip[2]arp->__ar_sip[3]?nast_hex_ntoa?(eptr->ether_shost));
???????}
?????break;
???case?8:
?????fprintf(logfile?“類型:?InARP?請求“);
?????break;
???case?9:
?????fprintf(logfile?“類型:?InARP?應答\t“);
?????break;
???default:
?????fprintf(logfile?“類型:?未知操作符“);
?????break;
??}
fprintf(logfile?“硬件大小:?%d?-?“?arp->ar_hln);
fprintf(logfile?“協議大小:?%d\n“?arp->ar_pln);
}
?else??if?(eptr->ether_type?==?ETHERTYPE_REVARP)
?{
fprintf(logfile?“\n---[?RARP?]----------------------------------------------------------\n“);
fprintf(logfile?“%s?->?“??nast_hex_ntoa?(eptr->ether_shost));
fprintf(logfile?“%s\n“?nast_hex_ntoa?(eptr->ether_dhost));
switch?(ntohs(arp->ar_op))
??{
???case?3:
?????fprintf(logfile?“類型:?RARP?請求“);
?????break;
???case?4:
?????fprintf(logfile?“類型:?RARP?應答\t“);
?????break;
???case?8:
?????fprintf(logfile?“類型:?InARP?請求“);
?????break;
???case?9:
?????fprintf(logfile?“類型:?InARP?應答\t“);
?????break;
???default:
?????fprintf(logfile?“類型:?未知操作符“);
?????break;
??}
fprintf(logfile?“\t硬件大小:?%d?-?“arp->ar_hln);
fprintf(logfile?“協議大小:?%d\n“arp->ar_pln);
?}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-02-14?02:59??src\
?????文件????????2680??2009-07-08?05:42??src\arp.c
?????文件????????2462??2009-07-08?05:42??src\common.c
?????文件?????????800??2009-07-08?05:24??src\device.c
?????文件?????????918??2009-07-07?13:15??src\ethernet.c
?????文件????????4977??2009-07-08?07:05??src\find_gateway.c
?????文件????????7581??2009-07-08?05:02??src\icmp.c
?????文件????????1965??2009-07-07?14:16??src\igmp.c
?????文件????????3730??2009-07-08?07:06??src\main.c
?????文件?????????112??2009-07-08?12:43??src\makefile
?????文件????????7828??2009-07-08?05:17??src\port.c
?????文件????????4052??2009-07-08?04:56??src\sniffer.c
?????文件????????2611??2009-07-08?06:28??src\sniffer.h
?????文件????????3776??2009-07-07?14:20??src\tcp.c
?????文件????????1834??2009-07-07?14:22??src\udp.c
?????文件??????247760??2019-02-14?02:56??src\sniffer
?????文件???????54431??2019-02-14?02:59??src\log.txt
- 上一篇:opencv2.4.4
- 下一篇:sx1276 sx1278 阻抗匹配設計指南
評論
共有 條評論