This software of mine should do the job:
http://code.google.com/p/badvpn/wiki/tun2socks
What you'd have to do is tell tun2socks to use your socks server, then adjust your routes to route your clients' traffic into tun2socks's TUN device; and tun2socks will forward it through SOCKS. However, be careful to make sure that the
address of the socks server is routed directly, not via the tun device (as that would make a loop).
If you want different routing for local connections, you may need to use policy routing (ip rule, iptables marks).