As an aside, the tun/tap interface in Linux is a fantastic way to muck around with lower-level networking without getting into the kernel or hardware. Essentially, it creates a virtual network interface, except instead of hardware, data goes to your userspace program. You can then just do a read() to grab packets and do whatever you want with them, using Python, Ruby, or anything other programming language.

I wrote a prototype proxy in Go that can split network traffic over two Internet connections using some hacked-together tun code[0] and everything happens in userspace.

[0] https://github.com/erjiang/tuntuntun

Yeah, I'm trying to tunnel TCP packets over Facebook chat[0] (to get some free Internet when using "social media" mobile plans).

[0] https://github.com/matiasinsaurralde/facebook-tunnel