Hi Remy
Thanks for your reply.
I have found a way to do this. Since I am already reading and parsing the
whole TCP and IP headers with the intermediate drivers, I can read that it
is in fact a "SYN" command sent to a http server. I then redirect this
packet to my idMappedTCPPort class listening on pert 9512.
I had to modify Indy's class to do the OnConnect event before it assigns a
"" to the outbound connections host. So in the OnConnect event I can set it.
Then I find the IP in a list containing all the IP's and PORTS which went
through my network monitor class:
(httpGateway is the idTCPMappedPort class)
procedure TdmHttpServer.httpGatewayConnect(AContext: TIdContext);
var
lClient: TIdMappedPortContext;
lsSourceIP: String;
lSourcePort, lDestPort: Integer;
tmpAddreses: TInAddresses;
s_IP: TInAddr;
s_Port, d_Port: Word;
lsMessage: String;
begin
lClient := TIdMappedPortContext(AContext);
lsSourceIP := lClient.Connection.Socket.Binding.PeerIP;
lSourcePort := lClient.Connection.Socket.Binding.PeerPort;
lDestPort := lClient.Connection.Socket.Binding.Port;
s_IP := StrToInAddr(lsSourceIP);
s_Port := htons(lSourcePort);
d_Port := htons(lDestPort);
if FindIP(s_IP.S_addr, s_Port, d_Port, tmpAddreses) then begin
TIdTcpClient(lClient.OutboundClient).Host :=
InAddrToStr(tmpAddreses.OriginalDestIP);
httpGateway.MappedHost := InAddrToStr(tmpAddreses.OriginalDestIP);
end;
end;
I am still fine tuning it but so far it works like a charm. Most (90%) of
the sites I tested loads, but for some reason others don't....
Regards
Hannes
Post by Remy Lebeau (TeamB)Post by Hannes GouwsCan anyone give me an example of how to use the
TidMappedPortTCP class for http ?
Since you are trying to delegate HTTP connections, you should try using
TIdHTTPProxyServer instead. HTTP has a CONNECT command specifically for
telling a proxy server where to connect to. TIdHTTPProxyServer handles
that command. TIdMappedPortTCP does not. In order to handle CONNECT with
TIdMappedPortTCP, you would have to manually read an entire HTTP packet in
the OnConnect event, validate that it is a CONNECT command, and configure
the TIdContext's OutboundClient.Host/Port properties as needed.
Also, you will have to configure your browser with proxy settings so it
knows to send the CONNECT command in the first place.
Gambit