PcapPlusPlus: Android fail to open wlan0

Question

Hello! I’m trying to use pcap++ with android. I build it using QT 6.5.3, NDK 25, Android API 30 on rooted device in permissive mode.

So, the problem is in this:

pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDeviceByName("wlan0");

This method tries to gets instance of wlan0 . Then I try to use it like this:

if (!dev->open())
    {
        std::cout << "Cannot open device" << std::endl;
        return 1;
    }

But the problem is, it always fails to open device. Any ideas to fix it? I’m thinking about monitor mode, but the thing is, when I enable monitor mode for wlan0, it stops being an live device and goes into read-only state.

Operating systems

Android

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 25 (7 by maintainers)

Most upvoted comments

Thanks for the help, issue closed

@seladb crafting my own rawpackets proved to be a working concept:

void packet_handler(u_char *user_data, const struct pcap_pkthdr *pkthdr, const u_char *packet) {
    uint8_t* packetData = new uint8_t[pkthdr->caplen];
	  memcpy(packetData, packet, pkthdr->caplen);
    pcpp::RawPacket* rawPacketPtr = new pcpp::RawPacket(packetData, pkthdr->caplen, pkthdr->ts, true);
    pcpp::Packet parsedPacket(rawPacketPtr);
    
    stats.consumePacket(parsedPacket);
    for (pcpp::Layer* curLayer = parsedPacket.getFirstLayer(); curLayer != NULL; curLayer = curLayer->getNextLayer()) {
      printf("\n====DATA BEGIN====\n");
      printf("String: %s\n", curLayer->toString().c_str());
      printf("Total data: %d\n", curLayer->getDataLen());
      printf("Layer data: %d\n", curLayer->getHeaderLen());
      printf("Layer payload: %d\n", curLayer->getLayerPayloadSize());
      printf("====DATA END====\n");
      }
}

image