- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
#include <pcap.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/if_ether.h>
#include <net/ethernet.h>
#include <netinet/ether.h>
struct usf
{
u_int8_t dest[6]; /* destination eth addr */
u_int8_t source[6]; /* source ether addr */
u_int16_t type;
u_int8_t tst[6]; /* source ether addr */
};
u_int16_t handle_ethernet
(u_char *args,const struct pcap_pkthdr* pkthdr,const u_char* packet);
void my_callback(u_char *args,const struct pcap_pkthdr* pkthdr,
const u_char* packet)
{
printf ("in my_callback function\n");
u_int16_t type = handle_ethernet(args,pkthdr,packet);
if(type == ETHERTYPE_IP)
{/* handle IP packet */
}else if(type == ETHERTYPE_ARP)
{/* handle arp packet */
}
else if(type == ETHERTYPE_REVARP)
{/* handle reverse arp packet */
}
}
u_int16_t handle_ethernet
(u_char *args,const struct pcap_pkthdr* pkthdr,
const u_char* packet)
{
struct usf *eptr; /* net/ethernet.h */
/* lets start with the ether header... */
eptr = (struct usf *) packet;
fprintf(stdout,"ethernet header source: %s\n"
,ether_ntoa((const struct ether_addr *)&eptr->source));
fprintf(stdout," destination: %s \n"
,ether_ntoa((const struct ether_addr *)&eptr->dest));
fprintf(stdout," tst : %s\n "
,ether_ntoa((const struct ether_addr *)&eptr->tst));
/* check to see if we have an ip packet */
if (ntohs (eptr->type) == ETHERTYPE_IP)
{
fprintf(stdout,"(IP)");
}else if (ntohs (eptr->type) == ETHERTYPE_ARP)
{
fprintf(stdout,"(ARP)");
}else if (ntohs (eptr->type) == ETHERTYPE_REVARP)
{
fprintf(stdout,"(RARP)");
}else {
fprintf(stdout,"(?)");
exit(1);
}
return eptr->type;
}
int main(int argc,char **argv)
{
char *dev; // interface name ex: wlan0
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t* descr;
struct bpf_program fp; /* hold compiled program */
bpf_u_int32 maskp; /* subnet mask */
bpf_u_int32 netp; /* ip */
u_char* args = NULL;
if(argc < 2){
fprintf(stdout,"Usage: %s numpackets \"options\"\n",argv[0]);
return 0;
}
/* grab a device to peak into... */
// dev = pcap_lookupdev(errbuf);
dev = "wlan0";
if(dev == NULL)
{ printf("%s\n",errbuf); exit(1); }
/* ask pcap for the network address and mask of the device */
pcap_lookupnet(dev,&netp,&maskp,errbuf);// return the ip of wlan0 and netmask
/* open device for reading. NOTE: defaulting to
* promiscuous mode*/
descr = pcap_create(dev,errbuf);
// descr = pcap_open_live(dev,BUFSIZ,1,-1,errbuf);
if(descr == NULL)
{ printf("pcap_open_live(): %s\n",errbuf); exit(1); }
if(pcap_set_rfmon(descr,1)!=0 )
{
printf("monitor mode enabled: %s\n",errbuf); exit(1);
}
pcap_activate(descr);
if(argc > 2)
{
if(pcap_compile(descr,&fp,argv[2],0,netp) == -1)
{ fprintf(stderr,"Error calling pcap_compile\n"); exit(1); }
if(pcap_setfilter(descr,&fp) == -1)
{ fprintf(stderr,"Error setting filter\n"); exit(1); }
}
int i= pcap_loop(descr,atoi(argv[1]),my_callback,args);
if(i==-1)
{
printf("error in pcap_loop\n"); exit(1);
}
else if (i==0)
{
printf(" 0 \n"); exit(1);
}
else if (i==-2)
{
printf(" -2 \n"); exit(1);
}
fprintf(stdout,"\nfinished\n");
return 0;
}
我需要做的就是将我的卡接口(interface)转换为监视模式,以嗅探信标帧以达到某些良好的目的,但是当在 pcap_creat 和 pcap_set_rfmon 之后使用 pcap 库时,pcap_loop 中的处理程序不起作用,所以任何人都可以帮助我知道什么问题是??
最佳答案
您可以使用libiw
获取/设置有关无线接口(interface)的信息(由iwconfig
命令使用)。
关于c - 在 pcap_creat 和 pcap_set_rfmon 之后使用 pcap 库,pcap_loop 中的处理程序不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20702918/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 5年前关闭。 Improve this qu
大家好,我如何收集 pcap 文件中每个数据包的数据包长度?非常感谢 最佳答案 我推荐一个很少有人知道的高科技方法:阅读文档。 man pcap 告诉我们实际上有两种不同的长度可用:
我在我的 linux 系统上安装了 pcap 库,但是当包含它时,我得到了错误 /usr/include/pcap/bpf.h:88:1: error: unknown type name ‘u_i
是否有任何简单的方法可以使用 tshark 为与特定日期时间范围相关的数据包创建 pcap 文件? , tcpdump或其他命令行工具? tshark -R与 frame.time看起来很有希望,但我
我有Tcpdump生成的“ .pcap”文件。我一直在寻找一种使用PHP读取文件中数据的方法。我尝试了几种可用的方法,但是我唯一能看到的是,有一些数据包带有针对每个数据包的时间戳记。我试图进一步阅读,
我有一个很大的 pcap 文件,我想生成一个仅包含前十分钟流量的新 pcap。我可以使用 tcpdump 执行此操作吗?我在网上看到过 editcap ,但如果可能的话我想使用 tcpdump 。 最
我有一个很大的 pcap 文件,我想生成一个仅包含前十分钟流量的新 pcap。我可以使用 tcpdump 执行此操作吗?我在网上看到过 editcap ,但如果可能的话我想使用 tcpdump 。 最
我从一个答案中阅读了文档: ntohs 函数采用 TCP/IP 网络字节顺序(AF_INET 或 AF_INET6 地址族)的 16 位数字,并以主机字节顺序返回一个 16 位数字。 请举例说明,什么
我有一堆通过 tcpdump 获得的 pcap 文件。我需要在所有文件中搜索特定关键字并记录哪些文件包含这些字符串。有没有办法使用 tcpdump 命令自动搜索这些关键字? 最佳答案 使用 tshar
我卡住了。 我使用 PCAP.NET 读取 .PCAP 文件并将数据包写入数据库。现在我可以查询数据库并取回与约束匹配的数据包。我需要一种方法将结果写入新的 .PCAP 文件。 问题是,据我所知,生成
我需要嗅探特定 Linux 用户 (UID) 的流量。我正在使用 iptables/NFLOG ( http://wiki.wireshark.org/CaptureSetup/NFLOG ) 来做这
作为我正在进行的实验室练习的一部分,有人问我; 使用 tcpdump 从 tcpdumpep1.pcap 读取数据包并过滤来自 IP 地址 184.107.41.72 和端口 80 的数据包。将这些数
有没有办法使用 Java 将 pcap-ng 文件转换为 pcap(不使用 editcap)? 我注意到一些 pcap 被读取为 .pcap 格式,但当我查看 Wireshark“摘要”时,它被识别为
已结束。此问题不符合 Stack Overflow guidelines .它目前不接受答案。 我们不允许提出有关书籍、工具、软件库等方面的建议的问题。您可以编辑问题,以便用事实和引用来回答它。 关闭
我正在用nodejs开发一个数据包捕获应用程序。 当我发出命令npm install pcap时,出现以下错误: 谁能帮我解决一下吗?谢谢 最佳答案 谢谢,这个( enter link descrip
我对JNetPcap很陌生,我仍在寻找它的方法,我正在尝试为我的项目构建一个数据包嗅探器,最近我正在尝试打印输出数据包信息通过附加我正在使用的 pcap.loop() 中的信息到 JTextArea
我有由 Tcpdump 生成的“.pcap”文件。我一直在寻找一种使用 PHP 读取文件中数据的方法。我已经尝试了几种可用的方法,但我唯一能看到的是有一定数量的数据包,每个数据包都有时间戳。我试图进一
如何确定通过 Makefile 编译/安装的 C 源代码中包含的 pcap.h 文件? 具体来说,它是一个通过以下方式安装的 Ruby 库 (pcaprub): ruby extconf.rb &&
运行“tcpdump -w 1.pcap”时需要限制文件大小。我尝试使用键“-C”来执行此操作,但是当我添加它时,我收到错误“权限被拒绝”。所以: > sudo tcpdump -w 1.pcap t
所以...我正在尝试使用RawCap捕获到本地主机的流量 当我运行rawcap时,它会在cmd提示符下报告数据包-但转储文件始终为空。 任何想法(我尝试使用admin privs运行) 最佳答案 您应
我是一名优秀的程序员,十分优秀!