[Solved] Implausible PING RTT with Synapse when using IPV6 lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- ArminLinder · 2023-03-25 20:34 Hi all, I use quite straightforward code to do a PING test, platform is Windows 10x64,  Lazarus 2.2.0, Laz_Synapse 40.1: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.DoPingSuccess(const aPingSender: TPingSend);begin  PingResultEdit.Text := Format('Success, RTT=%dms', [aPingSender.PingTime]);  RTTListChartSource.Add(now, aPingSender.PingTime);end; procedure TForm1.DoPingFailed(const aPingSender: TPingSend);begin  PingResultEdit.Text := Format('Failed, reason=%d (%s)', [aPingSender.ReplyError, aPingSender.ReplyErrorDesc]);  RTTListChartSource.Add(now, 0, 'F');end; procedure TForm1.doPing(anIP: string); var  PingSend: TPINGSend; begin  PingSend := TPingSend.Create;  if PingSend.Ping(anIp) then    doPingSuccess(Pingsend)  else    doPingFailed(PingSend);  FreeAndNil(PingSend);end; When I give it an IPV4 address, everything is fine. If I give it the IPV6 address (of the same host) or any other host I get RTT times of around 3000000ms, while "real" PING times are around 40ms. Before I wave the "Bug" flag of the Synapse project ... does anyone find an error in my code? Thnx, Armin. ---------------------------------------------------------------------- Thaddy · 2023-03-25 20:42 1) ping requests should be dropped by the server anyway. 2) Synapse has no real IPv6 support. What is your intention? then I can give a proper answer. ( ping being a well known - and very serious! - security risk: https://en.wikipedia.org/wiki/Ping_flood ) Why you want to use it? ---------------------------------------------------------------------- ArminLinder · 2023-03-25 22:44 Thaddy, I can for sure confirm that the target server does not have any ICMP bandwith throttling issue, since this code does give me the expected values for the RTT: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.doPing(anIP: string); var  PingSend: TPINGSend;  dt:TDateTime;  ms:word; begin  PingSend := TPingSend.Create;  dt := now();  if PingSend.Ping(anIp) then    begin    ms := MilliSecondsBetween(dt,now());    // doPingSuccess(Pingsend);    PingResultEdit.Text := Format('Success, RTT=%dms (%dms)', [PingSend.PingTime,ms]);    end  else    doPingFailed(PingSend);  FreeAndNil(PingSend);end; The results of this approach are almost the same as when testing with IPv4, and in the range between 40ms and say 200ms, which looks OK for me: "Success, RTT=2883584ms (47ms)" The objective of the code is quite simple: I need to test the connection to a remote server from time to time to make an instable VPN connection reconnect when it drops out. If I don't get an answer, I need to restart the VPN client. I ping the server once every minute, which should not cause any traffic issues. Accuracy to the millisecond is not required, and my workaround works sufficiently. Nevertheless I suspect there could be a bug in Synapse decoding the return values from the buffer returned by Windows, when IPV6 is in use. Armin. ---------------------------------------------------------------------- ArminLinder · 2023-03-26 10:21 Think I found it myself. There seems to be a bug in Synapse when mapping the ICMP response. The bytes are shifted by two, only IPV6 is affected. This code works: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     PingResultEdit.Text := Format('Success, RTT=%dms (%dms)', [PingSend.PingTime SHR 16,ms]);   The result is: "Success, RTT=40ms (31ms)", which makes perfect sense to me. I'll try to bring this issue to the attention of the Synapse team. (curiousity took over ... after some research, this is my theory) The bug lies in pingsend function TPINGSend.InternalPingIpHlp, line 614. (Here: Line 8.) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i       if pingIp6 then      begin        FillChar(ip6, sizeof(ip6), 0);        r := Icmp6SendEcho2(PingHandle, nil, nil, nil, @ip6, @Fsin,          PAnsichar(FBuffer), length(FBuffer), @ipo, pAnsichar(RBuff), length(RBuff), FTimeout);        if r > 0 then        begin          // --> RBuff := #0 + #0 + RBuff; <--          ip6reply := PICMPV6_ECHO_REPLY(pointer(RBuff));          FPingTime := ip6reply^.RoundTripTime;          ip6reply^.Address.sin6_family := AF_INET6;          FReplyFrom := GetSinIp(TVarSin(ip6reply^.Address));          TranslateErrorIpHlp(ip6reply^.Status);          Result := True;      end;      end  RBuff := #0 + #0 + RBuff; shifts the whole buffer by two bytes. I don't see any reason for this, maybe the author meant to code RBuff := RBuff + #0 + #0; to terminate the string. if I comment out his line, ping works flawlessly with IPV6. Since I don't like to compile my projects with modified libraries, I finally filed a bug in the Synapse Bugtracker (https://sourceforge.net/p/synalist/bugs/71/), and made this workaround: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.DoPingSuccess(const aPingSender: TPingSend); var pt: LongInt; begin  pt := aPingSender.PingTime;  // Synapse V40 bug? IPV6 PingTime seems to be shifted left by 2 bytes.  // A RTT of more than 65.5 seconds seems impossible  // trying to workaround the bug by reversing the shift  if pt > $FFFF then    pt := pt SHR 16;  PingResultEdit.Text := Format('Success, RTT=%dms', [pt]);  RTTListChartSource.Add(now,pt);end;  This gives me the results shown in the attachment. Armin. ---------------------------------------------------------------------- ArminLinder · 2023-03-26 17:46 Confirmed and fixed by the Snapse folks (Geby) within roughly an hour :-) I love Lazarus :-) Armin ---------------------------------------------------------------------- krolikbest · 2023-03-27 20:47 Thanks for info.