Hello everyone,
I'm building my own protocol for network communication on a windows machine. I've built a working wired version using the winpcap driver (it allows me to send raw packets). But now I want to extend this functionality to wireless networks. Does anyone perhaps know how/if I can send raw wireless packets? I've tried to do it with the winpcap driver, and although it seems to be working on the machine that's sending the data (no errors, wireshark shows packets being sent) nothing is received on the machine listening for packets. I verified that both machines were listening on the same channel.
Can somebody please help me?
The code I used to send on the wireless adapter:
code taken from http://www.codeproject.com/KB/IP/winpcap_basic.aspx
#include <pcap.h>
#include <iostream>
#include <windows.h>
int main(int argc, char* argv[]){
pcap_if_t * allAdapters;
pcap_if_t * adapter;
pcap_t * adapterHandle;
u_char packet[ 20 ];
char errorBuffer[ PCAP_ERRBUF_SIZE ];
if( pcap_findalldevs_ex( PCAP_SRC_IF_STRING, NULL,
&allAdapters, errorBuffer ) == -1 )
{
fprintf( stderr, "Error in pcap_findalldevs_ex function: %s\n",
errorBuffer );
return -1;
}
if( allAdapters == NULL )
{
printf( "\nNo adapters found! Make sure WinPcap is installed.\n" );
return 0;
}
int crtAdapter = 0;
for( adapter = allAdapters; adapter != NULL; adapter = adapter->next)
{
printf( "\n%d.%s ", ++crtAdapter, adapter->name );
printf( "-- %s\n", adapter->description );
}
printf( "\n" );
int adapterNumber;
printf( "Enter the adapter number between 1 and %d:", crtAdapter );
scanf( "%d", &adapterNumber );
if( adapterNumber < 1 || adapterNumber > crtAdapter )
{
printf( "\nAdapter number out of range.\n" );
pcap_freealldevs( allAdapters );
return -1;
}
adapter = allAdapters;
for( crtAdapter = 0; crtAdapter < adapterNumber - 1; crtAdapter++ )
adapter = adapter->next;
adapterHandle = pcap_open( adapter->name, 65536, PCAP_OPENFLAG_PROMISCUOUS, 1000, NULL, errorBuffer );
if( adapterHandle == NULL )
{
fprintf( stderr, "\nUnable to open the adapter\n", adapter->name );
pcap_freealldevs( allAdapters );
return -1;
}
pcap_freealldevs( allAdapters );
packet[0] = 0xFF;
packet[1] = 0xFF;
packet[2] = 0xFF;
packet[3] = 0xFF;
packet[4] = 0xFF;
packet[5] = 0xFF;
packet[6] = 0x02;
packet[7] = 0x02;
packet[8] = 0x02;
packet[9] = 0x02;
packet[10] = 0x02;
packet[11] = 0x02;
for( int index = 12; index < 20; index++ )
{
packet[index] = 0xC4;
}
while( true ){
if( pcap_sendpacket( adapterHandle, packet, 20 ) != 0 )
{
fprintf( stderr,"\nError sending the packet: \n", pcap_geterr( adapterHandle ) );
break;
}
Sleep(100);
}
system( "PAUSE" );
return 0;
}