Query SRV DNS records with DNSServiceQueryRecordMBS

I want to do query SRV DNS records to get information about Imap servers (email - Is there a standard DNS record to indicate the IMAP server for a domain? - Server Fault).

I think that DNSServiceQueryRecordMBS](Monkeybread Xojo plugin - DNSServiceQueryRecordMBS class).QueryRecord should work. But there is now example. How do I use DNSServiceQueryRecordMBS?

I’ll make an example.


Public Sub RunQuery(domain as string)
  Dim q As New DNSServiceQueryRecordMBS
  Const kDNSServiceType_MX = 15
  Const kDNSServiceClass_IN = 1
  AddHandler q.ServiceQueryRecord, WeakAddressOf ServiceQueryRecord
  If q.QueryRecord(0, domain, kDNSServiceType_MX, kDNSServiceClass_IN) Then
    queries.append q
    list.AddRow domain, "", "Failed to start query."
  End If
End Sub

and then parse result:

Public Sub ServiceQueryRecord(query as DNSServiceQueryRecordMBS, flags as integer, InterfaceIndex as integer, ErrorCode as integer, Fullname as string, rrType as Integer, rrClass as integer, Length as Integer, Data as string, ttl as Integer)
  If ErrorCode = 0 Then
    Dim d As MemoryBlock = data
    list.AddRow fullname, priority.ToString, name
    list.AddRow fullname, "", "Error: "+ErrorCode.ToString
  End If
End Sub
1 Like