DNS SRV Lookups on Linux from C#
The .NET framework’s System.Net.Dns class is incredibly lacking. It only supports the basic name to address and address to name functionality, while I needed to do an SRV lookup.
Looking around, I only found windows-only C# examples that used dnsapi, so I wrote a quick wrapper around glibc’s libresolv library.
$ gmcs -out:srv.exe -unsafe srv.cs $ ./srv.exe _xmpp-server._tcp.gmail.com 20 0 5269 xmpp-server2.l.google.com 20 0 5269 xmpp-server3.l.google.com 20 0 5269 xmpp-server4.l.google.com 5 0 5269 xmpp-server.l.google.com 20 0 5269 xmpp-server1.l.google.com
The code could be easily modified to support other DNS record types too. I think this would make a good addition to the Mono namespace somewhere.
The res_query() function is extremely annoying to use, and the documentation is almost non-existent. If there is a more modern API that I should be using instead, please let me know.
Categorized as Open Source, Mono, Open Source
This is exactly what I just needed. What an incredible luck :) Thank you very much.
The assembly from LumiSoft has pretty good DNS support, including SRV records. It also implements other protocols like IMAP.
http://www.lumisoft.ee/lsWWW/Download/Downloads/Net/
Nifty. This should probably go into svn or added to the the system library eh?