Hi,
I've never done networking through C programmation... but I've just seen an iptables target that could help if you agree to do a part of this in shell script.
There's a target called u32 which seems to enable you to match packets given any bit pattern in the header (
http://www.netfilter.org/documentat...ions-HOWTO.html)... thus you should be able redirect the packets you've previously modified.