资源简介
源.cpp
代码片段和文件信息
#define HAVE_REMOTE
#include
#include
#include
#include
#pragma comment(lib “Packet“)
#pragma comment(lib “wpcap“)
#pragma comment(lib “WS2_32“)
typedef struct ip_header {
u_char ver_ihl; // Version (4 bits) + Internet header length(4 bits)
u_char tos; // Type of service
u_short tlen; // Total length
u_short identification; // Identification
u_short flags_fo; // Flags (3 bits) + Fragment offset(13 bits)
u_char ttl; // Time to live
u_char proto; // Protocol
u_short crc; // Header checksum
u_char saddr[4]; // Source address
u_char daddr[4]; // Destination address
u_int op_pad; // Option + Padding
} ip_header;
typedef struct mac_header {
u_char dest_addr[6];
u_char src_addr[6];
u_char type[2];
} mac_header;
void packet_handler(u_char *param const struct pcap_pkthdr
*header const u_char *pkt_data);
int main()
{
pcap_if_t *alldevs;
pcap_if_t *d;
int inum;
int i = 0;
pcap_t *adhandle;
u_int netmask;
struct bpf_program fcode;
char errbuf[PCAP_ERRBUF_SIZE];
/* Retrieve the device list */
if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING NULL &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_s(“%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; i< inum - 1; d = d->next i++);
/* Open the adapter */
if ((adhandle = pcap_open(d->name 65536 PCAP_OPENFLAG_PROMISCUOUS 1000 NULL errbuf)) == NULL) {
fprintf(stderr “\nU
- 上一篇:步进电机上位机界面设计
- 下一篇:一定经纬范围的墨卡托投影.cpp
相关资源
- Steffensen.cpp
- vc++著名的木马程序BO2000源代码.rar
- 语音信号端点检测(VC++6.0)
- zw_duanzhiying-1870490-C语言库函数.zip
- zw_RSA算法C语言实现.zip
- zw_MFCCombox自动提示.zip
- 视觉识别特定草莓等其他水果
- welch功率谱的c语言程序.txt
- 蓝桥杯青少组C++赛前集训包.pdf
- L.CPP
- c++primer_第五版_中文版(完整).rar
- test_opencv.cpp
- CC语言程序设计课后答案.doc
- C语言程序设计KANDR版.pdf
- dft.cpp
- cc++项目视频.txt
- sanke.cpp
- iar.cc++.compiler.v1.30.3.50673.for.rl78-patch
- dos.cpp
- 红外避障小车程序C语言源码.rar
- main.cpp
- C++全方位学习》范磊高清pdf书+源代码
- c++21天课程.txt
- eig.cpp
- C语言试题库含答案.rar
- C语言课程设计学生成绩管理系统源码
- 尚观教育李慧芹Linux下C语言前嵌入式
- PN532-mfoc-mfcuk-GUI_V2.1.rar
- MFC折叠和展开窗口实现方法.txt
- 《从放弃C语言到使用C++刷算法的简明
评论
共有 条评论