I cross compiled this code for TP-Link mr 3020 with chaos calmer.
#include <stdio.h>
#include <pcap.h> // libpcap 1.5.3 is installed on OpenWrt
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
pcap_t *handle;
int status=0;
int header_type;
char errbuf[PCAP_ERRBUF_SIZE];
/* openwrt && linux */
char *dev=(char *)"wlan0";
handle=pcap_create(dev,errbuf);
if (handle == NULL) {
fprintf(stderr, "Couldn't open device %s: %s\n", dev, errbuf);
return 0;
}
if(pcap_set_rfmon(handle,1)!=0) {
fprintf(stderr, "Device %s couldn't be opened in monitor mode\n", dev);
return 0;
} else {
printf("Device %s has been opened in monitor mode\n", dev);
}
pcap_set_promisc(handle,0);
pcap_set_snaplen(handle,65535);
status=pcap_activate(handle); // This fails.
if(status!=0) {
pcap_perror(handle,(char*)"pcap error: ");
return 0;
}
header_type=pcap_datalink(handle);
if(header_type!=DLT_IEEE802_11_RADIO) {
printf("Error: incorrect header type - %d\n",header_type);
return 0;
}
}
Every time I run the installed binary on the router I get this error:
Device wlan0 has been opened in monitor mode
pcap error: : That device doesn't support monitor mode
`pcap_activate(handle);` function fails to activate the handle I have no idea why? Here is the make file:
include $(TOPDIR)/rules.mk
PKG_NAME:=opensniff
PKG_VERSION:=1.0.1
PKG_BUILD_DEPENDS:=libpcap
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/kernel.mk
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
define Package/opensniff
SECTION:=utils
CATEGORY:=Utilities
DEPENDS:=+libpcap
TITLE:=Test raditap header fields.
endef
define Package/$(PKG_NAME)/description
Test the network card for the radiotap fields it supports.
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
define Build/Compile
$(MAKE) -C $(PKG_BUILD_DIR) $(TARGET_CONFIGURE_OPTS)
endef
define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/bin
endef
$(eval $(call BuildPackage,$(PKG_NAME)))
How to fix this?