資源簡介
簡單的網絡嗅探器
Linux 下的socket 編程的實踐
libnet libcap 的應用
附簡單的項目文檔

代碼片段和文件信息
/*
?*?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);
?}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????615705??2009-10-04?17:03??項目報告1.pdf
?????文件???????2680??2009-07-08?13:42??src\arp.c
?????文件???????2462??2009-07-08?13:42??src\common.c
?????文件????????800??2009-07-08?13:24??src\device.c
?????文件????????918??2009-07-07?21:15??src\ethernet.c
?????文件???????4977??2009-07-08?15:05??src\find_gateway.c
?????文件???????7581??2009-07-08?13:02??src\icmp.c
?????文件???????1965??2009-07-07?22:16??src\igmp.c
?????文件???????3730??2009-07-08?15:06??src\main.c
?????文件????????112??2009-07-08?20:43??src\makefile
?????文件???????7828??2009-07-08?13:17??src\port.c
?????文件??????38158??2009-07-08?22:38??src\sniffer
?????文件???????4052??2009-07-08?12:56??src\sniffer.c
?????文件???????2611??2009-07-08?14:28??src\sniffer.h
?????文件???????3776??2009-07-07?22:20??src\tcp.c
?????文件???????1834??2009-07-07?22:22??src\udp.c
?????目錄??????????0??2009-08-09?14:35??src
-----------?---------??----------?-----??----
???????????????699189????????????????????17
- 上一篇:自己收藏的7個獎狀模板
- 下一篇:LaTex報告封面樣式-1
評論
共有 條評論