[fpc-pascal] fcl-web: Trequest.RemoteAddr is empty (sometimes)
Santiago A.
svaa at ciberpiula.net
Tue Jan 12 10:19:04 CET 2021
El 08/01/2021 a las 10:16, Luca Olivetti via fpc-pascal escribió:
> El 7/1/21 a les 16:59, Luca Olivetti via fpc-pascal ha escrit:
>> El 7/1/21 a les 16:15, Luca Olivetti via fpc-pascal ha escrit:
>>> Hello,
>>>
>>> I need to tailor the content based on the remote ip address.
>>> I use the property RemoteAddr of a TRequest, but sometimes it is empty.
>>> I see that it is a header, what I didn't see (yet, I'll trace
>>> through the code later) is if it is sent from the remote host or is
>>> it filled based on the ip address of the connection.
>>> If the former, is there a more reliable way to obtain the connected
>>> ip address?
>>> If the latter is it a bug?
>>
>> I now see that it set in TFPHTTPConnection.ReadRequestHeaders:
>>
>> Result.RemoteAddress := SocketAddrToString(FSocket.RemoteAddress)
>>
>> In turn SocketAddrToString returns an empty string if the address is
>> ipv6, but in my case it shouldn't be (the clients, firefox under
>> windows 10 uses the ipv4 address of the server and most of the time I
>> get the correct remote address, even from the same client).
>
> Besides, it seems that the server only listens on ipv4.
> I'm puzzled, I really can't see where this empty RemoteAddress could
> come from.
>
> Bye
In windows 10 when you connect to localhost, it may connect with IPV6
and route to ipv4 with weird results.
Try to connect using IP 127.0.0.1 http://127.0.0.1
You may also add in C:\Windows\System32\drivers\etc\hosts a line like
localhost4 127.0.0.1
and then http://localhost4
You may also disable IPV6 service if you don't use it. I have, because
it is seldom used, it looks like every device/system still works only
with IPV4
--
Saludos
Santiago A.
More information about the fpc-pascal
mailing list