資源簡(jiǎn)介
chujinlong110_7056173.rar

代碼片段和文件信息
#include?“pcap.h“
/*?prototype?of?the?packet?handler?*/
void?packet_handler(u_char?*param?const?struct?pcap_pkthdr?*header?const?u_char?*pkt_data);
main()
{
pcap_if_t?*alldevs;
pcap_if_t?*d;
int?inum;
int?i=0;
pcap_t?*adhandle;
char?errbuf[PCAP_ERRBUF_SIZE];
/*?Retrieve?the?device?list?*/
if(pcap_findalldevs(&alldevs?errbuf)?==?-1)
{
fprintf(stderr“Error?in?pcap_findalldevs:?%s\n“?errbuf);
exit(1);
}
/*?Print?the?list?*/
for(d=alldevs;?d;?d=d->next)
{
printf(“%d.?%s“?++i?d->name);
if?(d->description)
printf(“?(%s)\n“?d->description);
else
printf(“?(No?description?available)\n“);
}
if(i==0)
{
printf(“\nNo?interfaces?found!?Make?sure?WinPcap?is?installed.\n“);
return?-1;
}
printf(“Enter?the?interface?number?(1-%d):“i);
scanf(“%d“?&inum);
if(inum?1?||?inum?>?i)
{
printf(“\nInterface?number?out?of?range.\n“);
/*?Free?the?device?list?*/
pcap_freealldevs(alldevs);
return?-1;
}
/*?Jump?to?the?selected?adapter?*/
for(d=alldevs?i=0;?inext?i++);
/*?Open?the?device?*/
/*?Open?the?adapter?*/
if?((adhandle=?pcap_open_live(d->name //?name?of?the?device
?65536 //?portion?of?the?packet?to?capture.?
//?65536?grants?that?the?whole?packet?will?be?captured?on?all?the?MACs.
?1 //?promiscuous?mode?(nonzero?means?promiscuous)
?1000 //?read?timeout
?errbuf //?error?buffer
?))?==?NULL)
{
fprintf(stderr“\nUnable?to?open?the?adapter.?%s?is?not?supported?by?WinPcap\n“?d->name);
/*?Free?the?device?list?*/
pcap_freealldevs(alldevs);
return?-1;
}
printf(“\nlistening?on?%s...\n“?d->description);
/*?At?this?point?we?don‘t?need?any?more?the?device?list.?Free?it?*/
pcap_freealldevs(alldevs);
/*?start?the?capture?*/
pcap_loop(adhandle?0?packet_handler?NULL);
pcap_close(adhandle);
return?0;
}
/*?Callback?function?invoked?by?libpcap?for?every?incoming?packet?*/
void?packet_handler(u_char?*param?const?struct?pcap_pkthdr?*header?const?u_char?*pkt_data)
{
struct?tm?*ltime;
char?timestr[16];
time_t?local_tv_sec;
/*?convert?the?timestamp?to?readable?format?*/
local_tv_sec?=?header->ts.tv_sec;
ltime=localtime(&local_tv_sec);
strftime(?timestr?sizeof?timestr?“%H:%M:%S“?ltime);
printf(“%s%.6d?len:%d\n“?timestr?header->ts.tv_usec?header->len);
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????7702??2006-10-17?11:20??sniffer\WinPcap\docs\html\annotated.html
?????文件???????5418??2006-10-17?11:20??sniffer\WinPcap\docs\html\daemon_8h-source.html
?????文件???????3729??2006-10-17?11:20??sniffer\WinPcap\docs\html\daemon_8h.html
?????文件???????2253??2006-10-17?11:20??sniffer\WinPcap\docs\html\deprecated.html
?????文件???????1576??2006-10-17?11:20??sniffer\WinPcap\docs\html\doxygen.png
?????文件???????1096??2006-10-17?11:20??sniffer\WinPcap\docs\html\doxygen__groups_8txt.html
?????文件???????6353??2002-04-10?04:45??sniffer\WinPcap\docs\html\dump.gif
?????文件???????2777??2002-04-10?04:45??sniffer\WinPcap\docs\html\encoding.gif
?????文件???????4468??2006-10-17?11:20??sniffer\WinPcap\docs\html\fileconf_8h-source.html
?????文件???????3234??2006-10-17?11:20??sniffer\WinPcap\docs\html\fileconf_8h.html
?????文件???????3216??2006-10-17?11:20??sniffer\WinPcap\docs\html\files.html
?????文件????????174??2006-10-17?11:20??sniffer\WinPcap\docs\html\ftv2blank.png
?????文件????????255??2006-10-17?11:20??sniffer\WinPcap\docs\html\ftv2doc.png
?????文件????????259??2006-10-17?11:20??sniffer\WinPcap\docs\html\ftv2folderclosed.png
?????文件????????261??2006-10-17?11:20??sniffer\WinPcap\docs\html\ftv2folderopen.png
?????文件????????233??2006-10-17?11:20??sniffer\WinPcap\docs\html\ftv2lastnode.png
?????文件????????358??2006-10-17?11:20??sniffer\WinPcap\docs\html\ftv2li
?????文件????????160??2006-10-17?11:20??sniffer\WinPcap\docs\html\ftv2mlastnode.png
?????文件????????194??2006-10-17?11:20??sniffer\WinPcap\docs\html\ftv2mnode.png
?????文件????????235??2006-10-17?11:20??sniffer\WinPcap\docs\html\ftv2node.png
?????文件????????165??2006-10-17?11:20??sniffer\WinPcap\docs\html\ftv2plastnode.png
?????文件????????200??2006-10-17?11:20??sniffer\WinPcap\docs\html\ftv2pnode.png
?????文件????????229??2006-10-17?11:20??sniffer\WinPcap\docs\html\ftv2vertline.png
?????文件??????16542??2006-10-17?11:20??sniffer\WinPcap\docs\html\funcs_2pcap_8h-source.html
?????文件??????33856??2006-10-17?11:20??sniffer\WinPcap\docs\html\funcs_2pcap_8h.html
?????文件??????18384??2006-10-17?11:20??sniffer\WinPcap\docs\html\functions.html
?????文件??????18287??2006-10-17?11:20??sniffer\WinPcap\docs\html\functions_vars.html
?????文件??????35867??2006-10-17?11:20??sniffer\WinPcap\docs\html\globals.html
?????文件??????19612??2006-10-17?11:20??sniffer\WinPcap\docs\html\globals_defs.html
?????文件???????1517??2006-10-17?11:20??sniffer\WinPcap\docs\html\globals_enum.html
............此處省略361個(gè)文件信息
評(píng)論
共有 條評(píng)論