public static void DNSSRVRecordLookup(SIPSchemesEnum scheme, SIPProtocolsEnum protocol, string host, bool async, ref SIPDNSLookupResult lookupResult) { SIPServicesEnum reqdNAPTRService = SIPServicesEnum.none; if (scheme == SIPSchemesEnum.sip && protocol == SIPProtocolsEnum.udp) { reqdNAPTRService = SIPServicesEnum.sipudp; } else if (scheme == SIPSchemesEnum.sip && protocol == SIPProtocolsEnum.tcp) { reqdNAPTRService = SIPServicesEnum.siptcp; } else if (scheme == SIPSchemesEnum.sips && protocol == SIPProtocolsEnum.tcp) { reqdNAPTRService = SIPServicesEnum.sipstcp; } else if (scheme == SIPSchemesEnum.sip && protocol == SIPProtocolsEnum.tls) { reqdNAPTRService = SIPServicesEnum.siptls; } // If there are NAPTR records available see if there is a matching one for the SIP scheme and protocol required. SIPDNSServiceResult naptrService = null; if (lookupResult.SIPNAPTRResults != null && lookupResult.SIPNAPTRResults.Count > 0) { if (reqdNAPTRService != SIPServicesEnum.none && lookupResult.SIPNAPTRResults.ContainsKey(reqdNAPTRService)) { naptrService = lookupResult.SIPNAPTRResults[reqdNAPTRService]; } } // Construct the SRV target to lookup depending on whether an NAPTR record was available or not. string srvLookup = null; if (naptrService != null) { srvLookup = naptrService.Data; } else { srvLookup = "_" + scheme.ToString() + "._" + protocol.ToString() + "." + host; } SIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Unknown, SIPMonitorEventTypesEnum.DNS, "SIP DNS SRV record lookup requested for " + srvLookup + ".", null)); DNSResponse srvRecordResponse = DNSManager.Lookup(srvLookup, DNSQType.SRV, DNS_LOOKUP_TIMEOUT, null, true, async); if (srvRecordResponse == null && async) { SIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Unknown, SIPMonitorEventTypesEnum.DNS, "SIP DNS SRV record lookup pending for " + srvLookup + ".", null)); lookupResult.Pending = true; } else if (srvRecordResponse.Timedout) { SIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Unknown, SIPMonitorEventTypesEnum.DNS, "SIP DNS SRV record lookup timed out for " + srvLookup + ".", null)); lookupResult.SRVTimedoutAt = DateTime.Now; } else if (srvRecordResponse.Error != null) { SIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Unknown, SIPMonitorEventTypesEnum.DNS, "SIP DNS SRV record lookup for " + srvLookup + " returned error of " + lookupResult.LookupError + ".", null)); } else if (srvRecordResponse.Error == null && srvRecordResponse.RecordSRV != null && srvRecordResponse.RecordSRV.Length > 0) { foreach (RecordSRV srvRecord in srvRecordResponse.RecordSRV) { SIPDNSServiceResult sipSRVResult = new SIPDNSServiceResult(reqdNAPTRService, srvRecord.Priority, srvRecord.Weight, srvRecord.RR.TTL, srvRecord.Target, srvRecord.Port, DateTime.Now); lookupResult.AddSRVResult(sipSRVResult); SIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Unknown, SIPMonitorEventTypesEnum.DNS, "SIP DNS SRV record found for " + srvLookup + ", result " + srvRecord.Target + " " + srvRecord.Port + ".", null)); } } else { SIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Unknown, SIPMonitorEventTypesEnum.DNS, "SIP DNS no SRV records found for " + srvLookup + ".", null)); } }
public static void DNSNAPTRRecordLookup(string host, bool async, ref SIPDNSLookupResult lookupResult) { SIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Unknown, SIPMonitorEventTypesEnum.DNS, "SIP DNS NAPTR record lookup initiated for " + host + ".", null)); // Target is a hostname with no explicit port, DNS lookup for NAPTR records. DNSResponse naptrRecordResponse = DNSManager.Lookup(host, DNSQType.NAPTR, DNS_LOOKUP_TIMEOUT, null, true, async); if (naptrRecordResponse == null && async) { lookupResult.Pending = true; } else if (naptrRecordResponse.Timedout) { lookupResult.NAPTRTimedoutAt = DateTime.Now; } else if (naptrRecordResponse.Error == null && naptrRecordResponse.RecordNAPTR != null && naptrRecordResponse.RecordNAPTR.Length > 0) { foreach (RecordNAPTR naptrRecord in naptrRecordResponse.RecordNAPTR) { SIPDNSServiceResult sipNAPTRResult = new SIPDNSServiceResult(SIPServices.GetService(naptrRecord.Service), naptrRecord.Order, 0, naptrRecord.RR.TTL, naptrRecord.Replacement, 0, DateTime.Now); lookupResult.AddNAPTRResult(sipNAPTRResult); SIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Unknown, SIPMonitorEventTypesEnum.DNS, "SIP DNS NAPTR record found for " + host + ", result " + naptrRecord.Service + " " + naptrRecord.Replacement + ".", null)); } } else { SIPMonitorLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Unknown, SIPMonitorEventTypesEnum.DNS, "SIP DNS no NAPTR records found for " + host + ".", null)); } }
public void AddSRVResult(SIPServicesEnum service, RecordSRV srvRecord) { //logger.Debug("Adding record for " + URI.ToString() + " " + srvRecord.ToString() + "."); SIPDNSServiceResult sipSRVResult = new SIPDNSServiceResult(service, srvRecord.Priority, srvRecord.RR.TTL, srvRecord.Target, srvRecord.Port, DateTime.Now); if (SIPSRVResults == null) { SIPSRVResults = new List<SIPDNSServiceResult>() { sipSRVResult }; } else { SIPSRVResults.Add(sipSRVResult); } }
public static SIPDNSLookupResult DNSARecordLookup(SIPDNSServiceResult nextSRVRecord, string host, int port, bool async, SIPURI lookupURI) { if (nextSRVRecord != null && nextSRVRecord.Data != null) { return DNSARecordLookup(nextSRVRecord.Data, port, async, lookupURI); //nextSRVRecord.ResolvedAt = DateTime.Now; } else { return DNSARecordLookup(host, port, async, lookupURI); } }
public void AddNAPTRResult(RecordNAPTR naptrRecord) { //logger.Debug("Checking NAPTR record for " + URI.ToString() + " " + naptrRecord.ToString() + "."); SIPServicesEnum sipServicesEnum = SIPServicesEnum.none; if (naptrRecord.Service == SIPDNSManager.NAPTR_SIP_UDP_SERVICE) { sipServicesEnum = SIPServicesEnum.sipudp; } else if (naptrRecord.Service == SIPDNSManager.NAPTR_SIP_TCP_SERVICE) { sipServicesEnum = SIPServicesEnum.siptcp; } else if (naptrRecord.Service == SIPDNSManager.NAPTR_SIPS_TCP_SERVICE) { sipServicesEnum = SIPServicesEnum.sipstcp; } if(sipServicesEnum != SIPServicesEnum.none) { //logger.Debug(" adding NAPTR lookup result for " + URI.ToString() + " of " + naptrRecord.ToString() + "."); SIPDNSServiceResult sipNAPTRResult = new SIPDNSServiceResult(sipServicesEnum, naptrRecord.Order, naptrRecord.RR.TTL, naptrRecord.Replacement, 0, DateTime.Now); if (SIPNAPTRResults == null) { SIPNAPTRResults = new Dictionary<SIPServicesEnum, SIPDNSServiceResult>() { { sipServicesEnum, sipNAPTRResult } }; } else { SIPNAPTRResults.Add(sipServicesEnum, sipNAPTRResult); } } }