Discussion:
TidMappedPortTCP
(too old to reply)
Hannes Gouws
2008-06-20 07:18:53 UTC
Permalink
Hi

Can anyone give me an example of how to use the TidMappedPortTCP class for
http ?

Thanks
Remy Lebeau (TeamB)
2008-06-20 16:43:51 UTC
Permalink
Post by Hannes Gouws
Can 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
Hannes Gouws
2008-06-20 19:41:07 UTC
Permalink
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 Gouws
Can 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
Remy Lebeau (TeamB)
2008-06-20 19:57:59 UTC
Permalink
Post by Hannes Gouws
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.
No, you did not have to change Indy's source code for that. The OnConnect
event was already being triggered before the internal TIdTCPClient is
connected to the next server. You can override the Host and Port properties
in OnConnect just fine as-is.
Post by Hannes Gouws
httpGateway.MappedHost := InAddrToStr(tmpAddreses.OriginalDestIP);
You don't need to do that. The MappedHost property is only used to
initialize the TIdTCPClient.Host property before triggering the OnConnect
event. By reassigning it like that, you are not effecting the current
connection at all, but are effecting what is assigned to the next
connection. Since you have to do per-connection overrides anyway, there is
no point in assigning the MappedHost at all, not even at design-time.


Gambit

Loading...