title: Sending packets without network connection (wireless adapter)
body: <p>I have to send packets with a wifi adapter to another computer without connecting to any network, targeting Windows 7 and above. First of all, ad-hoc (as I understand) doesn't fit my needs because it requires connection. </p>
  
  <p>I had two ideas:</p>
  
  <ol>
  <li><p>create something similar to a broadcast packet which identify networks. This can be used on wireless card</p></li>
  <li><p>send fake but valid packet and which doesn't
  need a specific IP/MAC address (they can be broadcasts for example).</p></li>
  </ol>
  
  <p>What I use: C# with a Win7 PC and a Win7 laptop for testing the program. SharpPcap to send packets. Wireshark to check if they are arrived.</p>
  
  <p>I tried the second method:</p>
  
  <pre><code>static void Main(string[] args)
  {
      WinPcapDeviceList devs = WinPcapDeviceList.Instance;
      foreach (WinPcapDevice wdev in devs)
      {
          System.Console.Write("Device: ");
          System.Console.WriteLine(wdev.Description);
          foreach (var addr in wdev.Addresses)
              System.Console.WriteLine(addr.Addr);
          System.Console.WriteLine("--------------");
      }
  
      System.Console.Write("Select device: #");
      int selected = int.Parse(System.Console.ReadLine());
      var dev = devs[selected]; //yes, no checking for oob...
      dev.Open();
  
      while (true)
      {
          byte[] physBroad = new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
          EthernetPacket etherPacket = new EthernetPacket(
              dev.MacAddress,
              new PhysicalAddress(physBroad),
              EthernetPacketType.IpV4);
  
          IPv4Packet ip4Packet = new IPv4Packet(
              new IPAddress(0),
              IPAddress.Broadcast);
  
          ip4Packet.Protocol = IPProtocolType.UDP;
  
          etherPacket.PayloadPacket = ip4Packet;
  
          UdpPacket udpPacket = new UdpPacket(
              80, //tried with different port setups
              80);
  
          udpPacket.PayloadData = Encoding.UTF8.GetBytes("test packet");
          ip4Packet.PayloadPacket = udpPacket;
  
          dev.SendPacket(etherPacket);
      }
  }
  </code></pre>
  
  <p>Without connecting to the same network they are discarded (not arrive at Wireshark). I can only see the packets if they are on the same network.</p>
  
  <p>For the first one, I know about IEEE 802.11, but I can't find anything about how to craft and send those packets. Is it possible to do this without dedicated hardware like AirPcap? I'd like to avoid writing a driver too if not necessary.</p>
  
  <p>ps:
  I have an Edimax Wireless LAN card in my PC, and a Mediatek MT763E 802.11bgn Wifi-Adapter in my laptop. I installed the same version of Wireshark on both of them, but I can't turn the monitor mode on, and cannot set the link-layer type to IEEE-802.11, only to Ethernet and DOCSIS types.</p>