title: Programming a Packet Blocker (basic firewall) in C++ for Windows
body: <p>I am interested in programming a basic firewall that blocks packets according to user-defined rules.</p>
  
  <p>Basically, I already programmed the part that deals with the rules and everything is okay, but now I'm supposed to implement the firewall itself (the hard part, I guess).</p>
  
  <p>I searched a lot, and found a couple of links full of details e.g <a href="http://www.codeproject.com/Articles/3405/Developing-Firewalls-for-Windows-XP" rel="nofollow">this</a> and <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa366510%28v=vs.85%29.aspx" rel="nofollow">this</a>. The second (Windows Filtering Platform) seems most relevant, now, there doesn't seem to be any data about ACTUALLY getting started, the code snippets in the site (well, in this specific subject) don't explain the subject all too well.</p>
  
  <p>I would like to know simply how to block a packet matching a certain rule, so that includes a couple of stages:</p>
  
  <ol>
  <li><p>Listening for ANY incoming packets, all ports, IPs and protocols.</p></li>
  <li><p>Checking if the packet matches the certain rules.</p></li>
  <li><p>If it <strong>does</strong> match, let it through. If it <strong>doesn't</strong>, capture it and block it over there.</p></li>
  </ol>
  
  <p>Now, stage 2 is actually already programmed, I just need to match it according to stage 1 (what class/structure is used to represent the packet). I'm not sure about doing stage 1, and stage 3.</p>
  
  <p>First, how do I even listen to ALL of the connections in the computer?</p>
  
  <p>Second, how do I manage the packet I captured, letting it through OR blocking it.</p>
  
  <p>Help would be much appreciated. I mean raw WinAPI, but if there's a certain good API that works on windows (8, in specific) I'd be happy to test it.</p>