Linux contains a mechanism for doing this and a lot more called
netfilter. When building the kernel, it can be excluded, but it is present is kernels which ship with most mainstrean distros.
iptables is a tool used to configure netfilter. There are other tools to do the same thing, which may be more user-friendly. You don't need to write a C program to configure netfilter - just to use one of these tools.
If you're looking for a nice GUI which provides basic personal firewall type configuration options, take a look at
firestarter. There are plenty of others too - you're sure to find something which fits your needs.