資源簡介
linux下c (一個簡單的sniffer工具)
代碼片段和文件信息
/***************SimpelSniffer.c*************/
#include?
#include?
#include?
#include?
#include?
#include?
#define?BUFFER_MAX?2048
int?main(int?argc?char?*argv[])
{
int?sock?n_read?proto;
char?buffer[BUFFER_MAX];
char?*ethhead?*iphead?*tcphead?*udphead?*icmphead?*p;
if((sock?=?socket(PF_PACKET?SOCK_RAW?htons(ETH_P_IP)))?0)
{
fprintf(stdout?“create?socket?error\n“);
exit(0);
}
while(1)?
{
n_read?=?recvfrom(sock?buffer?2048?0?NULL?NULL);
/*
14???6(dest)+6(source)+2(type?or?length)
+
20???ip?header?
+
8????icmptcp?or?udp?header
=?42
*/
if(n_read?42)?
{
fprintf(stdout?“Incomplete?header?packet?corrupt\n“);
continue;
}
ethhead?=?buffer;
p?=?ethhead;
int?n?=?0XFF;
printf(“MAC:?%.2X:%02X:%02X:%02X:%02X:%02X==>“
“%.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n“
p[6]&n?p
評論
共有 條評論