Forum

× CodeTyphon Platforms (Win, GTK2/3, QT4/5, Cocoa, etc) Development, discussions and problems

Idea [bug report] bug on sending http request on Android

  • rarnu
  • rarnu's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
More
5 days 20 hours ago #12307 by rarnu
Sir, I have made a library for Android use CT6.50 and found that is BUG in netdb.pp

the file is located in "/usr/local/codetyphon/fpcsrc/packages/fcl-net/src/netdb.pp"

when compile for Android, it use these code for DNS:
Function GetDNSServers: Integer;
var
  i: integer;
  s: string;
  H : THostAddr;
begin
  Result:=0;
  SetLength(DNSServers, 9);
  for i:=1 to 9 do
    begin
      try
        s:=GetSystemProperty(PAnsiChar('net.dns' + IntToStr(i)));
      except
        s := '';
      end;
      if s = '' then
        break;
      H:=StrToNetAddr(s);
      if H.s_bytes[1] <> 0 then
        begin
          DNSServers[Result]:=H;
          Inc(Result);
        end;
    end;
  SetLength(DNSServers, Result);
end;

But on Android O and later, Google banned call to "net.dns", these code will take no affect and returns empty DNS server.

My solution is to add a default DNS Server and make it work again.
Function GetDNSServers: Integer;
var
  i: integer;
  s: string;
  H : THostAddr;
begin
  Result:=0;
  SetLength(DNSServers, 9);
  for i:=1 to 9 do
    begin
      try
        s:=GetSystemProperty(PAnsiChar('net.dns' + IntToStr(i)));
      except
        s := '';
      end;
      if s = '' then
        break;
      H:=StrToNetAddr(s);
      if H.s_bytes[1] <> 0 then
        begin
          DNSServers[Result]:=H;
          Inc(Result);
        end;
    end;
  if (Result = 0) then begin
    H := StrToNetAddr('8.8.8.8');
    DNSServers[0]:=H;
    Inc(Result);
  end;
  SetLength(DNSServers, Result);
end;

Then, the library on Android O and later works fine.

Would CT6.60 take my suggestion and fix the bug? B) B) B)

Please Log in or Create an account to join the conversation.

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
More
5 days 14 hours ago #12308 by Sternas Stefanos
Replied by Sternas Stefanos on topic [bug report] bug on sending http request on Android
Thanks Sir
we add your fix to LAB CT 6.6 in file
codetyphon/fpcsrc/packages/fcl-net/src/netdb.pp"

CodeTyphon Architect and Programmer
Attachments:

Please Log in or Create an account to join the conversation.