PureBasic Forum
http://forums.purebasic.com/english/

DNS Resolve
http://forums.purebasic.com/english/viewtopic.php?f=15&t=69986
Page 1 of 1

Author:  kinglestat [ Sat Jan 20, 2018 10:51 am ]
Post subject:  DNS Resolve

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:
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:
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?

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/