private static void V6Release() { DhcpV6Message msg = new DhcpV6Message(IPAddress.Any, new IPEndPoint(serverAddr, serverPort)); msg.SetTransactionId(-1729018559); DhcpV6ClientIdOption dhcpClientId = new DhcpV6ClientIdOption(); dhcpClientId.GetOpaqueData().SetAscii("000100011dd31327001dbac1557b"); msg.PutDhcpOption(dhcpClientId); DhcpV6ServerIdOption dhcpServerId = new DhcpV6ServerIdOption(); dhcpServerId.GetOpaqueData().SetAscii("000100011dd31327001dbac1557b"); msg.PutDhcpOption(dhcpServerId); msg.SetMessageType(DhcpConstants.V6MESSAGE_TYPE_RELEASE); msg.SetIaNaOptions(new List <DhcpV6IaNaOption>() { new DhcpV6IaNaOption(new v6IaNaOption() { iaId = 285220282, t1 = 0, t2 = 0 }) }); var message = DhcpV6MessageHandler.HandleMessage( serverAddr, msg); Console.WriteLine(message.ToString()); }
public DhcpV6Message ProcessMessage() { try { if (!PreProcess()) { log.Warn("Message dropped by preProcess"); return(null); } if (log.IsDebugEnabled) { log.Debug(("Processing: " + this.requestMsg.ToStringWithOptions())); } else if (log.IsInfoEnabled) { log.Info(("Processing: " + this.requestMsg.ToString())); } // build a reply message using the local and remote sockets from the request this.replyMsg = new DhcpV6Message(this.requestMsg.GetLocalAddress(), this.requestMsg.GetRemoteAddress()); // copy the transaction ID into the reply replyMsg.SetTransactionId(this.requestMsg.GetTransactionId()); // MUST put Server Identifier DUID in ADVERTISE or REPLY message replyMsg.PutDhcpOption(dhcpServerIdOption); // copy Client Identifier DUID if given in client request message replyMsg.PutDhcpOption(this.requestMsg.GetDhcpClientIdOption()); if (!Process()) { log.Warn("Message dropped by processor"); return(null); } if (log.IsDebugEnabled) { log.DebugFormat("Returning: {0}", this.replyMsg.ToStringWithOptions()); } else if (log.IsInfoEnabled) { log.InfoFormat("Returning: {0}", this.replyMsg.ToString()); } } finally { if (!this.PostProcess()) { log.Warn("Message dropped by postProcess"); this.replyMsg = null; } } return(this.replyMsg); }
public DHCPv6SendMessage(int transactionId) { DhcpV6MessagePacket = new DhcpV6Message(IPAddress.Any, new IPEndPoint(IPAddress.Parse("ff02::1:2"), DEST_PORT)); DhcpV6MessagePacket.SetTransactionId(transactionId); DhcpV6ClientIdOption dhcpClientId = new DhcpV6ClientIdOption(); dhcpClientId.GetOpaqueData().SetHex(new byte[] { 0x00, 0x01, 0x00, 0x01, 0x20, 0x39, 0xBB, 0x3F, 0x98, 0x5F, 0xD3, 0x58, 0x7D, ++duid }); //.SetAscii("000100011dd31327001dbac1557b"); DhcpV6MessagePacket.PutDhcpOption(dhcpClientId); DhcpV6ElapsedTimeOption dhcpElapsedTime = new DhcpV6ElapsedTimeOption(); dhcpElapsedTime.SetUnsignedShort(1); DhcpV6MessagePacket.PutDhcpOption(dhcpElapsedTime); }
public override DhcpV6Message AddOtherOptions(DhcpV6Message dhcpV6MessagePacket) { DhcpV6Message replyDhcpV6Message = new DhcpV6Message(null, null); byte[] replyData = _replyPacke.GetData(); replyDhcpV6Message.Decode(ByteBuffer.allocate(replyData.Length).put(replyData).flip()); dhcpV6MessagePacket.SetMessageType(DhcpConstants.V6MESSAGE_TYPE_REQUEST); dhcpV6MessagePacket.PutDhcpOption(replyDhcpV6Message.GetDhcpServerIdOption()); dhcpV6MessagePacket.SetIaNaOptions(replyDhcpV6Message.GetIaNaOptions()); return(dhcpV6MessagePacket); }