WinPcap.zip

  • mfxxx
    了解作者
  • Visual C++
    开发工具
  • 7KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 10 积分
    下载积分
  • 1
    下载次数
  • 2018-05-10 17:39
    上传日期
收集网络流量的统计信息,利用这个功能来监视网络
WinPcap.zip
  • WinPcap
  • prj9
  • prj9.cpp
    5.3KB
  • prj9.vcxproj
    4KB
  • prj9.vcxproj.user
    143B
  • prj9.vcxproj.filters
    942B
  • prj9.suo
    9.5KB
  • prj9.sln
    879B
内容介绍
/* * Copyright (c) 1999 - 2002 * Politecnico di Torino. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, (2) * distributions including binary code include the above copyright notice and * this paragraph in its entirety in the documentation or other materials * provided with the distribution, and (3) all advertising materials mentioning * features or use of this software display the following acknowledgement: * ``This product includes software developed by the Politecnico * di Torino, and its contributors.'' Neither the name of * the University nor the names of its contributors may be used to endorse * or promote products derived from this software without specific prior * written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include "pcap.h" #pragma comment(lib, "wpcap") void dispatcher_handler(u_char *, const struct pcap_pkthdr *, const u_char *); void main(void) { pcap_t *fp; char error[PCAP_ERRBUF_SIZE]; struct timeval st_ts; u_int netmask; struct bpf_program fcode; pcap_if_t *alldevs,*d; int i=0,inum; /* 获得网卡的列表 */ if (pcap_findalldevs(&alldevs, error) == -1) { fprintf(stderr,"Error in pcap_findalldevs: %s\n", error); exit(1); } /* 打印网卡信息 */ 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 ; } printf("Enter the interface number (1-%d):",i); scanf("%d", &inum);//输入要选择打开的网卡号 if(inum < 1 || inum > i) //判断号的合法性 { printf("\nInterface number out of range.\n"); pcap_freealldevs(alldevs); /* Free the device list */ return ; } /* 找到要选择的网卡结构 */ for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++); /* 打开选择的网卡 */ if((fp = pcap_open_live(d->name, 100, 1, 1000, error) ) == NULL) { fprintf(stderr,"\nError opening adapter: %s\n", error); return; } /* Don't care about netmask, it won't be used for this filter */ netmask=0xffffff; //compile the filter if(pcap_compile(fp, &fcode, "tcp", 1, netmask)<0 ) { fprintf(stderr,"\nUnable to compile the packet filter. Check the syntax.\n"); return; } //set the filter if(pcap_setfilter(fp, &fcode)<0) { fprintf(stderr,"\nError setting the filter.\n"); return; } pcap_setmode(fp, MODE_STAT); /* 将网卡设置为统计模式 */ printf("TCP traffic summary:\n"); /* Start the main loop */ pcap_loop(fp, 0, dispatcher_handler,(PUCHAR)&st_ts); return; } void dispatcher_handler(u_char *state, const struct pcap_pkthdr *header, const u_char *pkt_data) { struct timeval *old_ts = (struct timeval *)state; u_int delay; LARGE_INTEGER Bps,Pps; struct tm *ltime; char timestr[16]; /* 从最近一次的采样以微秒计算延迟时间 */ /* This value is obtained from the timestamp that the associated with the sample. */ delay=(header->ts.tv_sec - old_ts->tv_sec) * 1000000 - old_ts->tv_usec + header->ts.tv_usec; /* 获得每秒的比特数 */ Bps.QuadPart=(((*(LONGLONG*)(pkt_data + 8)) * 8 * 1000000) / (delay)); /* ^ ^ | | | | | | converts bytes in bits -- | | delay is expressed in microseconds -- */ /* 获得每秒的数据包数 */ Pps.QuadPart=(((*(LONGLONG*)(pkt_data)) * 1000000) / (delay)); /* 将时间戳转变为可读的标准格式 */ ltime=localtime(&header->ts.tv_sec); strftime( timestr, sizeof timestr, "%H:%M:%S", ltime); printf("%s ", timestr); /* Print timestamp*/ /* Print the samples */ printf("BPS=%I64u ", Bps.QuadPart); printf("PPS=%I64u\n", Pps.QuadPart); //store current timestamp old_ts->tv_sec=header->ts.tv_sec; old_ts->tv_usec=header->ts.tv_usec; }
评论
    相关推荐
    • HX711.rar
      HX710芯片驱动电路,10kg传感器初步测试电路,称重,去皮
    • hx8347.rar
      Hx8347参考驱动,能驱动用Hx8347驱动IC 的2.8寸屏
    • 3.HX711串口STM32例程.zip
      基于stm32f103C8T6单片机的应变片式称重平台程序,其中包含hx711串口驱动程序。
    • HX8347.zip
      HX8347 display driver
    • hx8347 驱动 FSMC
      液晶HX8347的STM32驱动 FSMC HX8347.c HX8347.h HX8347_API.c font8x16.h delay.c delay.H readme.txt
    • hx-terraform
      terraform的打字稿EDSL 该存储库包含实现用于生成的嵌入式域特定语言(EDSL)的库代码。 目录结构如下: core/ providers/ tools/ library/ core/包含EDSL核心,并且独立于terraform提供商。...
    • HX711.rar
      5kg电子秤。实验电子秤、邮政电子秤、厨房电子秤等一般选用双孔悬臂平行 梁应变式称重传感器。它的特点是: 精度高、易加工、结构简单紧凑、 抗偏载能力强、固有频率高,
    • HX711.zip
      THIS IS DUCUMENT HX711 IN C
    • HX711.zip
      提供一个arduino的hx711的库文件,可以用于进行压力传感器的使用。
    • HX711-master.zip
      HX711 driver for embeded microcontroller