Just curious if this is possible. Lets assume i run a pair of irc servers (or anything else) on a system with different ports- i'd like to have something listen into a single port, and forward packets based on hostname - any connections to A.foo.bar should be forwarded to one port, and any connections to B.foo.bar should be forwarded to another. Most proxies seem to be for http, and well, that's not the use case i have in mind.
I'm currently running ubuntu server 9.04 and 10.04, though i'd be willing to switch to another free OS to do this.
I'm assuming that A.foo.bar and B.foo.bar resolve to the same IP.
There wouldn't be any way to do it without some sort of Application Layer proxying. You could use an HTTP or a SOCKS proxy connection on your clients so you can switch the connection based on hostname. You could probably also set up an IRC MitM that detects the hostname the client is trying to connects to, then handsoff to the correct server, but I don't know if the IRC protocol would provide enough info to do that.
You could use SQUID as a transparent proxy to accomplish this. It doesn't have to be HTTP.
But really, you have two different hostnames. You can point them to two different IPs and DNAT the traffic accordingly.