public static string[] GetSRVRecords(string needle) { IntPtr ptr1 = IntPtr.Zero; IntPtr ptr2 = IntPtr.Zero; SRVRecord recSRV; if (Environment.OSVersion.Platform != PlatformID.Win32NT) { throw new NotSupportedException(); } ArrayList list1 = new ArrayList(); try { int num1 = SRVLookup.DnsQuery(ref needle, QueryTypes.DNS_TYPE_SRV, QueryOptions.DNS_QUERY_BYPASS_CACHE, 0, ref ptr1, 0); if (num1 != 0) { if (num1 == 9003) { list1.Add(NETWORK_SRV_ERROR_CONFIG_SERVICE); } else { Win32Exception ex = new Win32Exception(num1); _log.Error("SRVLookup.GetSRVRecords: an exception occured during lookup. Details: " + ex.Message); return(new string[] { SRVLookup.NETWORK_SRV_ERROR_CONFIG_SERVICE }); } } for (ptr2 = ptr1; !ptr2.Equals(IntPtr.Zero); ptr2 = recSRV.pNext) { recSRV = (SRVRecord)Marshal.PtrToStructure(ptr2, typeof(SRVRecord)); if (recSRV.wType == (short)QueryTypes.DNS_TYPE_SRV) { string text1 = Marshal.PtrToStringAuto(recSRV.pNameTarget); text1 += ":" + recSRV.wPort; list1.Add(text1); } } } finally { SRVLookup.DnsRecordListFree(ptr1, 0); } return((string[])list1.ToArray(typeof(string))); }
public static ACEConfig LookupConfig(string address, string userName, string password) { string srvLookupUrl = "_rueconfig._tls."; srvLookupUrl += address; // concat with selected domain // cjm-sep17 -- just to save the example string to file //ACEConfig configToSave = JsonFactoryConfig.defaultConfig(ACEConfigStatusType.SRV_RECORD_NOT_FOUND); //JsonFactoryConfig.SaveDefaultConfig(JsonConvert.SerializeObject(configToSave, Formatting.Indented), JsonFactoryConfig.GetConfigFile()); string[] srvRecords = SRVLookup.GetSRVRecords(srvLookupUrl); if (srvRecords.Length > 0) { string record = srvRecords[0]; if (!record.Equals(SRVLookup.NETWORK_SRV_ERROR_CONFIG_SERVICE)) { string requestUrl = "https://" + srvRecords[0] + "/config/v1/config.json"; ACEConfig config = JsonFactoryConfig.createConfigFromURL(requestUrl, userName, password); return(config); } else { // cjm-sep17 -- this at least a test for local hhtp with auth server // this must be running on my local machine // https://localhost:443/Linphone/config/v1/config.json //IPHostEntry hostInfo = Dns.GetHostEntry("_sip._tcp.rueconfig.ddns.net"); //IPAddress localAddress = hostInfo.AddressList[0]; //string[] data = SRVLookup.GetSRVRecords("_sip._tcp.rueconfig.ddns.net"); string requestUrl = string.Empty; if (address == "sip.linphone.org") { requestUrl = "https://localhost:443/Linphone/config/v1/config.json"; } else { requestUrl = "https://localhost:443/ACL/config/v1/config.json"; } ACEConfig config = JsonFactoryConfig.createConfigFromURL(requestUrl, userName, password); return(config); } } return(JsonFactoryConfig.defaultConfig(ACEConfigStatusType.SRV_RECORD_NOT_FOUND)); }