figiel / hosts

a libc wrapper providing per-user hosts file

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Host with port

denisshevchenko opened this issue · comments

Hi!

Could you help me please? Your solution is amazing, but I need not the only IP, I need to specify some port as well. So I want to change file ~/.hosts like this:

127.0.0.1:8080  www.my-domain.com

As I understand it's impossible for now. But can you give me some advices how it can be implemented?

Hi Denis,
I don't think the approach I taken will work here, as I guess it won't be easy to directly correlate connect() calls (in which the port number is used for outgoing connections) with gethostbyname & friends to make it work in all cases (if you are fine with this working most of the time you could have some state in the preloaded library so that next call to connect() after gethostbyname() will result in a substitution of the port number).
I'm not sure what exactly you want to achieve but if you want to route HTTP connections only you may want to add aliases (e.g. www.my-domain.com from your example) to some single host and run a redirection service on it which would understand Host: HTTP header and redirect the requests by using that value. Browsers put hostnames to Host: headers as typed by the user.
I think you could actually configure Apache's httpd to do that (mod_rewrite comes to my mind).

Ok, thanks.