title: C# & Pcap.Net - Forwarding received packets
body: <p>First I'm using Visual Studio 2012 with C# and the Pcap.Net Library.
  I try to to forward packets which I captured before.</p>
  
  <p>What I try to do:</p>
  
  <ol>
  <li>Spoof ARP-Table of my phone.</li>
  <li>Redirect the traffic which normally goes to the gateway to my computer.</li>
  <li>Log the packets.</li>
  <li>Forward them to the gateway.</li>
  </ol>
  
  <p>What I did:</p>
  
  <ol>
  <li>Spoofing ARP-Table -> works fine.</li>
  <li>Redirect traffic to my PC -> works fine (logically).</li>
  <li>Log the packets to a dumpfile (.pcap) as shown in the tutorial on this site -> works fine (I can open it and read it with wireshark and it looks good).</li>
  <li>Forward the packets to the gateway. -> <strong>does not work.</strong></li>
  </ol>
  
  <p>I would like to forward them fluently. So what I did was use the "sendBuffer()" function as shown in the tutorial. So I just read in the .pcap file where all the packet information is saved and try to resend it with this "sendBuffer()" function. And of course I use the same adapter to do it.
  When I capture the traffic with wireshark I can see that my packets don't even get sent.
  (I'm also not sure if it works at the same time while I capture the data to the file. Because the code which should forward them need to read the packets from the file. <strong>Isn't there another way?</strong>)
  My code to forward the packets from the .pcap file (the IDE doesn't give me any error):
  It's approximately my code, I don't have it available cause I'm not at home. But should be right.</p>
  
  <pre><code>IList&lt;LivePacketDevice&gt; devices = LivePacketDevice.AllLocalMachine;
  PacketDevice selectedOutputDevice = devices[0];
  long capLength = new FileInfo(@"E:\CSharp\Pcap\dumpFile.pcap").Length;
  bool isSync = true;
  OfflinePacketDevice selectedInputDevice = new OfflinePacketDevice(@"E:\CSharp\Pcap\dumpFile.pcap");
              using (PacketCommunicator inputCommunicator = selectedInputDevice.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000))
              {
                  using (PacketCommunicator outputCommunicator = selectedOutputDevice.Open(100, PacketDeviceOpenAttributes.Promiscuous, 1000))
                  {
                      if (inputCommunicator.DataLink != outputCommunicator.DataLink)
                      {
                         tB_Log.Text = tB_Log.Text + Environement.NewLine + "ERROR: Different Datalinks!";
                      }
                      using (PacketSendBuffer sendBuffer = new PacketSendBuffer((uint)capLength))
                      {
                          Packet packet;
                          while (inputCommunicator.ReceivePacket(out packet) == PacketCommunicatorReceiveResult.Ok)
                          {
                              sendBuffer.Enqueue(packet);
                          }
  outputCommunicator.Transmit(sendBuffer, isSync);
  }
  }
  }
  </code></pre>
  
  <p>Thank you very much for helping!</p>