结构
pcap_if_tdheadNULLpcap_tfp网卡描叙符错误信息子网掩码
9
charerrbufPCAP_ERRBUF_SIZEu
sig
edi
t
etmask
fcharpacket_filter”ip”structbpf_programfcodestructpcap_pkthdrheaderco
stu
sig
edcharpkt_dataifpcap_fi
dalldevsalldevserrbuf
过滤,选择IP协议
获取网络设备列表1
cout”Errori
pcap_fi
dalldevs”errbufretur
i
ti0ifi0cout”
Noi
terfacesfou
dMakesurewi
Pacpisi
stalled
”retur
网卡数无设备
ifi1i
tj0fordalldevsddd
extcoutj””d
ameifddescriptio
cou
t““ddescriptio
e
dlcout”
E
eterthei
terface
umber1“j””i
tk
10
列出网卡列表,让用户进行选择
fci
k
ifk1kjcout”outofra
ge”e
dlretur
fordalldevsi1ikdd
extiheadd找到选择的网卡
以混杂模式打开网卡iffppcap_ope
_livehead
ame100011000errbufNULLcout”
U
abletoope
theadapter”e
dlpcap_freealldevsalldevsretur
获得子网掩码ifheadaddressesNULL
edmaskstructsockaddr_i
headaddresses
etmasksi
_addrs_u
s_addrelse没有地址假设为C类地址
etmask0xffffff
11
f编译过滤器ifpcap_compilefpfcodepacket_filterl
etmask0cout”
U
abletocompilethepacketfilterCheckthesy
tax
”pcap_freealldevsalldevsretur
设置过滤器ifpcap_setfilterfpfcode0cout”
Eeeorsetti
gthefilter
”pcap_freealldevsalldevsretur
显示提示信息及每项含义cout”ttliste
i
go
“headdescriptio
”…”e
dle
dlofstreamfoutargv2iosapp日志记录文件
fout”tIPStatistic“mi
”mi
utes”e
dltime_ttmptimeNULLfoutctimetmpcout”IPStatistic“mi
”mi
utes”e
dlfout”SourIP“”tpacket
umbers”e
dl
释放设备列表pcap_freealldevsalldevsNodeListli
k存储数据用链表
12
fi
trestime_tbegtime_te
dtimebeg获得当前时间
whilerespcap_
ext_exfpheaderpkt_data0timee
dife
dbegmi
60breakifres0co
ti
ueip_headerih找到IP头位置ihip_headerpkt_data14li
kaddNodeihsaddrcout”SourIPli
kpri
tcoutli
kpri
tfoutfoute
dl“’t’”packet
umbers”e
dl输出到屏幕输出到日志文件14为以太头的长度将源IP地址假如链表超时获得系统时间计算系统时间
13
f七.总结
做这个课题找了很多资料,感觉资料多就顺手的多。但也不能盲目相信找来的资料,要通过自己的验证没错误后才能用。不但是于此,别的任何学习方面也一样。我从中学到了许多新的知识,而且通过这次课程设计,培养了我综合多门学科中的知识r