As far as 'making' a software level filtering firewall goes, try seeing how others work as well. You might want to look into iptables (*nix) and it's switches.
Secondly, how do you close access to your ports?
You might want to ellaborate a little bit on this statement as well...
OS ?
Stand-Alone Machine ?
Service ?

Firstly, is a firewall solely for stopping people from connecting to your ports or does it do other stuff as well?
I'd love to help you with that question, but different firewalls work differently, and of course there are different types. Hardware firewalls and Software based.
In the link below is a small *Hardware And Software* debate..
http://www.smallbusinesscomputing.co...le.php/3103431
PM me if you need any other help..