I have been trying to inject packets into my wireless interface through libpcap for quite a while now. I am able to see the same packets when I check for packets from same interface, but no other interface or machine is able to get the packets.
In order to demonstrate what I mean, here's a small snippet of code I am using:
u_char RADIOTAP_WRAPPER[] = {
0x00, // it_version
0x00, // padding
0x0a, 0x00, // length
0x00, 0x00, 0x80, 0x00, // IEEE80211_RADIOTAP_TX_FLAGS
0x00, 0x08, // no-ack required
};
u_char my_packet[] = {
// Some custom data of mine that I want to send (and no, I don't want to use IEEE 802.11
};
u_char *complete_packet; // Concatenate the header and the my_packet data and place it here (skipping that code for brevity)
pcap_sendpacket(handle,complete_packet,complete_packet_size);
The packet is created properly, and if I run a receiver using pcap_next
on the same device (wlan0 in my case), it works perfectly. However, if I use wlan0 on a nearby device, or wlan1 on my own device, the packet is missing. The problem is not other packets in the wireless space, but the fact that the packets don't seem to get into space at all. They seem to be stuck inside the same interface.
Is there some specific flags I might be missing in the radiotap header? Something else?
PS: I am doing the custom data format for educational reasons only. I would prefer to not have the IEEE 802.11 header since it seems to go against what I plan to be building (a way of sending and receiving packets from and to anywhere w/o needing to know the person you are sending to). Hence, I would prefer that answers like "You should not be making your own packet header types etc" to not be there. Thanks :)
You cannot leave out the 802.11 header if you want an 802.11 network interface to read your packet. When a receiving network interface tries to read your packet, it will check whether it is a recipient (either directly, or for a broadcast, or if set to promiscuous mode). Also, 802.11 has a cyclic redundancy check (CRC) to verify that no transmission errors have occurred. If the place where it expects to read the CRS is not the correct hash value, the receiver will discard your packet.
I am not sure whether you are actually sending your packet over the air. You should be able to check this by running a sniffer on the receiver, for which you want to set monitor mode, promiscuous mode, and reading of packets that fail the CRC.