Page 1 of 1

DNS Resolve

Posted: Sat Jan 20, 2018 10:51 am
by kinglestat
Hello Guys,

I have recently started coding under linux and have ported some tools with very little difficulty; except now I am stuck on DNS
Under windows I can resolve with API

Code: Select all

Procedure.s ReverseDnsQuery(IP.i)
  Protected Name$ = "", *Record.DNS_RECORD
  Protected Query$ = Str((IP>>24) & $FF)+"."+Str((IP>>16) & $FF)+"."+Str((IP>>8) & $FF)+"."+Str(IP & $FF)+".IN-ADDR.ARPA" ; ip must be reversed!
  
  If DnsQuery_W And DnsRecordListFree
    If DnsQuery_W(Query$, #DNS_TYPE_PTR, #DNS_QUERY_STANDARD, #Null, @*Record.DNS_RECORD, #Null) = 0 And *Record
      If *Record\wType = #DNS_TYPE_PTR
        Name$ = PeekS(*Record\PTR\pNameHost, -1, #PB_Unicode)
      EndIf 
      DnsRecordListFree(*Record, #DnsFreeRecordList)
    EndIf
  EndIf
  
  ProcedureReturn Name$  
EndProcedure
Under linux

Code: Select all

pid      = RunProgram( "dig", "-x " + ip + " +short +tries=1 +time=" + Trim( Str( gDNSWait ) ), "", #PB_Program_Open | #PB_Program_Read )
         output   = ""
         
         If pid
            While ProgramRunning( pid )
               If AvailableProgramOutput( pid )
                  
                  temp = ReadProgramString( pid )
                  j = CountString( temp, "." )
                  
                  If j > max
                     max = j
                     output = Left(temp, Len(temp) - 1 )
                  EndIf
                  
               EndIf
            Wend
          
            CloseProgram( pid ) ; Close the connection to the program  
         EndIf
The difference is extraordinary - windows less than 1 second, under linux from 38 to 71 seconds!
Can someone help?