我有规则设置丢弃带匹配字符串的udp/tcp数据包.但是,我使用libpcap捕获数据包的程序仍能看到这个数据包.
为什么这个/,在libpcap看到之前丢弃数据包的iptable规则应该是什么?
无论如何,或许除了iptables规则之外,在libpcap/tcpdump看到它之前丢弃这个数据包?
我试图在Windows 7上的cygwin下安装libpcap,但我有这个错误:$ ./configure.....configure:error:有关详细信息,请参阅INSTALL
我怎么能解决这个问题?我使用的是libpcap-1.0.0,这是最新版本.
sniffex.c 是一个基于libpcap的程序,用于嗅探和显示一些数据包信息.如何修改它以便打印TCP标志的值 - urg,ack,psh,rst,syn和fin?请帮忙..
代码无法找到任何设备,我想知道pcap_lookupdev()做了什么?谢谢
#include <pcap.h>
int main(int argc, char *argv[])
{
pcap_t *handle;
char *dev;// = "eth0";
char errbuf[PCAP_ERRBUF_SIZE];
dev = pcap_lookupdev(errbuf);
if (dev == NULL) {
fprintf(stderr, "Couldn't find default device: %s\n", errbuf);
return(2);
}
printf("Device: %s\n", dev);
return(0);
handle = pcap_open_live(dev, BUFSIZ, 1, 1000, errbuf);
if (handle == NULL) {
fprintf(stderr, "Couldn't open device %s: %s\n", dev, errbuf);
return(2);
}
}
Run Code Online (Sandbox Code Playgroud) 的pcap_lookupdev()在errbuf可变填充时作为非超级用户运行,而相同功能时root运行返回第一个可用的网络接口的值.
操作系统或库是否禁用此访问权限.我认为这是操作系统.什么是正确的答案?
这不是一个家庭作业问题
我正在通过pcap和无线工作.根据我之前的问题回复发布的示例,我试图从无线帧中提取mac地址.我已经为radiotap头和基本管理框架创建了结构.出于某种原因,当涉及到尝试输出mac地址时,我打印出错误的数据.当我与wireshark比较时,我不明白为什么无线电数据打印正确但mac地址不正确.当我查看数据包并比较我捕获的数据包时,我看不到wireshark显示的十六进制转储中的任何额外填充.我有点熟悉c但不是专家所以也许我没有正确使用指针和结构有人可以帮助告诉我我做错了什么?
谢谢,昆汀
// main.c
// MacSniffer
//
#include <pcap.h>
#include <string.h>
#include <stdlib.h>
#define MAXBYTES2CAPTURE 65535
#ifdef WORDS_BIGENDIAN
typedef struct frame_control
{
unsigned int subtype:4; /*frame subtype field*/
unsigned int protoVer:2; /*frame type field*/
unsigned int version:2; /*protocol version*/
unsigned int order:1;
unsigned int protected:1;
unsigned int moreDate:1;
unsigned int power_management:1;
unsigned int retry:1;
unsigned int moreFrag:1;
unsigned int fromDS:1;
unsigned int toDS:1;
}frame_control;
struct ieee80211_radiotap_header{
u_int8_t it_version;
u_int8_t it_pad;
u_int16_t it_len;
u_int32_t it_present;
u_int64_t MAC_timestamp;
u_int8_t flags;
u_int8_t dataRate; …Run Code Online (Sandbox Code Playgroud) 必须将-lpcap与gcc一起使用来编译libpcap程序,但我不知道此标志的含义。有谁能够帮助我??
例:
$ gcc lpcap_demo.c -o lpcap_output.o -lpcap
谢谢!!!
我正在使用pcap_findalldevs获取计算机中的设备列表.我成功了,设备的名称和描述,但我不知道为什么,我得到Netmask 0.0.0.0和IP地址也0.0.0.0.这是我生成列表的代码:
/* get the devices list */
if (pcap_findalldevs(&devList, errbuf) == -1)
{
fprintf(stderr, "There is a problem with pcap_findalldevs: %s\n", errbuf);
return -1;
}
/* scan the list for a suitable device to capture from */
for (dev = devList; dev != NULL; dev = dev->next)
{
pcap_addr_t *dev_addr; //interface address that used by pcap_findalldevs()
/* check if the device captureble*/
if ((dev_addr = dev->addresses) != NULL && dev_addr->addr->sa_family == AF_INET && dev_addr->addr && dev_addr->netmask) {
printf("Found a …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个程序,用于读取Mac OS X(当前版本10.9.5)上的UDP数据包的IP地址和端口(在本例中为localhost).
给我一些有用数据的唯一一个是tcpdump和nc(netcat),但它只工作了一次.这就是我所做的:
1°终端窗口
$ sudo tcpdump -i en0 -X -v 'udp port 60000'
tcpdump: listening on en0, link-type EN10MB (Ethernet), capture size 65535 bytes
* new packet with the string 'Hello' at the end *
Run Code Online (Sandbox Code Playgroud)
2°终端窗口
$ nc -u 192.168.1.67 60000
Hello
$
Run Code Online (Sandbox Code Playgroud)
我对这个论点没有太多的了解,所以最后的问题是:
如果我需要创建一个程序,需要读取给定端口号的任何UDP数据包并通过同一端口将UDP数据包发送到任何IP地址,那么最简单的方法是什么?我试图通过C使用libpcap,但没有成功.
我试图使用libpcap查看TCP有效负载信息.为此,我需要在内存中找到有效负载的位置.我正在使用这个Programming With Pcap指南来确定请求有效负载的位置.嗅探源自与服务(环回适配器)位于同一台机器上的客户端的数据包时,IP标头长度为0.我无法成功找到请求有效负载的位置.听循环适配器时会出现这种情况吗?我正在使用MacOSx 10.8系统监听适配器'lo0'.
这是我正在尝试的:
//this callback is called when a packet is found
void got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet){
ethernet = (struct sniff_ethernet*)(packet);
ip = (struct sniff_ip*)(packet + SIZE_ETHERNET); <-- the result is 0
size_ip = IP_HL(ip)*4;
if (size_ip < 20) {
printf(" * Invalid IP header length: %u bytes\n", size_ip);
return;
}
tcp = (struct sniff_tcp*)(packet + SIZE_ETHERNET + size_ip);
size_tcp = TH_OFF(tcp)*4;
if (size_tcp < 20) {
printf(" * Invalid TCP …Run Code Online (Sandbox Code Playgroud)