/// <summary> /// Send an dynamic update to the dns server and returns the answer as an asynchronous operation. /// </summary> /// <param name="message"> Update, that should be send to the dns server </param> /// <param name="token"> The token to monitor cancellation requests </param> /// <returns> The complete response of the dns server </returns> public Task<DnsUpdateMessage> SendUpdateAsync(DnsUpdateMessage message, CancellationToken token = default(CancellationToken)) { if (message == null) throw new ArgumentNullException(nameof(message)); if (message.ZoneName == null) throw new ArgumentException("Zone name must be provided", nameof(message)); return SendMessageAsync(message, token); }
/// <summary> /// Send an dynamic update to the dns server and returns the answer. /// </summary> /// <param name="message"> Update, that should be send to the dns server </param> /// <returns> The complete response of the dns server </returns> public DnsUpdateMessage SendUpdate(DnsUpdateMessage message) { if (message == null) throw new ArgumentNullException(nameof(message)); if (message.ZoneName == null) throw new ArgumentException("Zone name must be provided", nameof(message)); return SendMessage(message); }
} // End Sub Test3 // Send dynamic update public static void Test4() { DnsUpdateMessage msg = new DnsUpdateMessage() { ZoneName = DomainName.Parse("example.com") }; msg.Updates.Add(new DeleteRecordUpdate(DomainName.Parse("dyn.example.com"), RecordType.A)); msg.Updates.Add(new AddRecordUpdate(new ARecord(DomainName.Parse("dyn.example.com"), 300, IPAddress.Parse("192.0.2.42")))); msg.TSigOptions = new TSigRecord(DomainName.Parse("my-key"), TSigAlgorithm.Md5, DateTime.Now, new TimeSpan(0, 5, 0), msg.TransactionID, ReturnCode.NoError, null, Convert.FromBase64String("0jnu3SdsMvzzlmTDPYRceA==")); DnsUpdateMessage dnsResult = new DnsClient(IPAddress.Parse("192.0.2.1"), 5000).SendUpdate(msg); } // End Sub Test4
/// <summary> /// Send an dynamic update to the dns server and returns the answer asynchronously. /// </summary> /// <param name="message"> Update, that should be send to the dns server </param> /// <param name="requestCallback"> /// An <see cref="System.AsyncCallback" /> delegate that references the method to invoked then the operation is complete. /// </param> /// <param name="state"> /// A user-defined object that contains information about the receive operation. This object is passed to the /// <paramref /// name="requestCallback" /> /// delegate when the operation is complete. /// </param> /// <returns> /// An <see cref="System.IAsyncResult" /> IAsyncResult object that references the asynchronous receive. /// </returns> public IAsyncResult BeginSendUpdate(DnsUpdateMessage message, AsyncCallback requestCallback, object state) { if (message == null) { throw new ArgumentNullException("message"); } if (String.IsNullOrEmpty(message.ZoneName)) { throw new ArgumentException("Zone name must be provided", "message"); } return(BeginSendMessage(message, requestCallback, state)); }
/// <summary> /// Send an dynamic update to the dns server and returns the answer. /// </summary> /// <param name="message"> Update, that should be send to the dns server </param> /// <returns> The complete response of the dns server </returns> public DnsUpdateMessage SendUpdate(DnsUpdateMessage message) { if (message == null) { throw new ArgumentNullException("message"); } if (String.IsNullOrEmpty(message.ZoneName)) { throw new ArgumentException("Zone name must be provided", "message"); } return(SendMessage(message)); }
public DnsUpdateMessage CreateResponseInstance() { DnsUpdateMessage result = new DnsUpdateMessage() { TransactionID = TransactionID, IsEDnsEnabled = IsEDnsEnabled, IsQuery = false, OperationCode = OperationCode, Questions = new List <DnsQuestion>(Questions), }; if (IsEDnsEnabled) { result.EDnsOptions.Version = EDnsOptions.Version; result.EDnsOptions.UdpPayloadSize = EDnsOptions.UdpPayloadSize; } return(result); }
internal static DnsMessageBase CreateByFlag(byte[] data, DnsServer.SelectTsigKey tsigKeySelector, byte[] originalMac) { int flagPosition = 2; ushort flags = ParseUShort(data, ref flagPosition); DnsMessageBase res; switch ((OperationCode)((flags & 0x7800) >> 11)) { case OperationCode.Update: res = new DnsUpdateMessage(); break; default: res = new DnsMessage(); break; } res.ParseInternal(data, tsigKeySelector, originalMac); return(res); }
internal static DnsMessageBase CreateByFlag(byte[] data) { int flagPosition = 2; ushort flags = ParseUShort(data, ref flagPosition); DnsMessageBase res; switch ((OperationCode)((flags & 0x7800) >> 11)) { case OperationCode.Update: res = new DnsUpdateMessage(); break; default: res = new DnsMessage(); break; } res.ParseInternal(data); return(res); }
public static DnsMessageBase Create(byte[] resultData, bool isRequest, DnsServer.SelectTsigKey tsigKeySelector, byte[] originalMac) { int flagPosition = 2; ushort flags = ParseUShort(resultData, ref flagPosition); DnsMessageBase res; switch ((OperationCode)(flags & 0x7800)) { case OperationCode.Update: res = new DnsUpdateMessage(); break; default: res = new DnsMessage(); break; } res.Parse(resultData, isRequest, tsigKeySelector, originalMac); return(res); }
public override bool unregisterService(ServiceName serviceName) { DomainName dnsName = serviceName.toDnsName(); DomainName typeName = DomainName.Parse(serviceName.getType().toDnsString()) + registrationDomain; List <DomainName> subtypes = new List <DomainName>(serviceName.getType().getSubtypes().Count); foreach (String subtype in serviceName.getType().toDnsStringsWithSubtype()) { subtypes.Add(DomainName.Parse(subtype) + registrationDomain); } DnsUpdateMessage msg = new DnsUpdateMessage(); msg.ZoneName = registrationDomain; // XXX Should really be the zone (SOA) for the RRs we are about to add msg.Prequisites.Add(new RecordExistsPrequisite(dnsName, RecordType.Any)); msg.Updates.Add(new DeleteRecordUpdate(new PtrRecord(typeName, timeToLive, dnsName))); foreach (DomainName subtype in subtypes) { msg.Updates.Add(new DeleteRecordUpdate(new PtrRecord(subtype, timeToLive, dnsName))); } msg.Updates.Add(new DeleteAllRecordsUpdate(dnsName)); TSigRecord tsigRecord = generateTSigRecord(msg.TransactionID); if (tsigRecord != null) { msg.TSigOptions = tsigRecord; } DnsUpdateMessage response = resolver.SendUpdate(msg); if (response != null) { switch (response.ReturnCode) { case ReturnCode.NoError: //flushCache(update); break; case ReturnCode.YXDomain: // Prerequisite failed, the service already exists. return(false); default: throw new DnsSDException("Failed to send DNS update to server. Server returned error code: " + response.ReturnCode.ToString()); } } else { throw new DnsSDException("Failed to send DNS update to server. Server time out"); } // Remove the service type if there are no instances left msg = new DnsUpdateMessage(); msg.ZoneName = registrationDomain; // XXX Should really be the zone (SOA) for the RRs we are about to add msg.Prequisites.Add(new RecordNotExistsPrequisite(typeName, RecordType.Any)); msg.Updates.Add(new DeleteRecordUpdate(new PtrRecord(servicesName, timeToLive, typeName))); tsigRecord = generateTSigRecord(msg.TransactionID); if (tsigRecord != null) { msg.TSigOptions = tsigRecord; } response = resolver.SendUpdate(msg); if (response != null) { switch (response.ReturnCode) { case ReturnCode.NoError: //flushCache(update); Log.Info(String.Format("Removed service type record {0}", typeName)); break; case ReturnCode.YXDomain: // Prerequisite failed, service instances exists Log.Info(String.Format("Did not remove service type record {0}, instances left.", typeName)); break; default: Log.Error(String.Format("Failed to remove service type {0}, server returned status {1}", typeName, response.ReturnCode.ToString())); break; } } else { throw new DnsSDException("Failed to send DNS update to server. Server time out"); } return(true); }
public override bool registerService(ServiceData serviceData) { ServiceName serviceName = serviceData.getName(); DomainName dnsName = serviceName.toDnsName(); DomainName typeName = DomainName.Parse(serviceName.getType().toDnsString()) + registrationDomain; List <DomainName> subtypes = new List <DomainName>(serviceName.getType().getSubtypes().Count); foreach (String subtype in serviceName.getType().toDnsStringsWithSubtype()) { subtypes.Add(DomainName.Parse(subtype) + registrationDomain); } DomainName target = DomainName.Parse(serviceData.getHost()); List <String> strings = new List <String>(); foreach (var entry in serviceData.getProperties()) { StringBuilder sb = new StringBuilder(); sb.Append(entry.Key); if (entry.Key != null) { sb.Append('=').Append(entry.Value); } strings.Add(sb.ToString()); } if (strings.Count <= 0) { // Must not be empty strings.Add(""); } DnsUpdateMessage msg = new DnsUpdateMessage(); msg.ZoneName = registrationDomain; // XXX Should really be the zone (SOA) for the RRs we are about to add msg.Prequisites.Add(new RecordNotExistsPrequisite(dnsName, RecordType.Any)); msg.Updates.Add(new AddRecordUpdate(new PtrRecord(servicesName, timeToLive, typeName))); msg.Updates.Add(new AddRecordUpdate(new PtrRecord(typeName, timeToLive, dnsName))); foreach (DomainName subtype in subtypes) { msg.Updates.Add(new AddRecordUpdate(new PtrRecord(subtype, timeToLive, dnsName))); } msg.Updates.Add(new AddRecordUpdate(new SrvRecord(dnsName, timeToLive, 0, 0, Convert.ToUInt16(serviceData.getPort()), target))); msg.Updates.Add(new AddRecordUpdate(new TxtRecord(dnsName, timeToLive, strings))); TSigRecord tsigRecord = generateTSigRecord(msg.TransactionID); if (tsigRecord != null) { msg.TSigOptions = tsigRecord; } DnsUpdateMessage response = resolver.SendUpdate(msg); if (response != null) { switch (response.ReturnCode) { case ReturnCode.NoError: //flushCache(update); return(true); case ReturnCode.YXDomain: // Prerequisite failed, the service already exists. return(false); default: throw new DnsSDException("Failed to send DNS update to server. Server returned error code: " + response.ReturnCode.ToString()); } } else { throw new DnsSDException("Failed to send DNS update to server. Server time out"); } }