private void BuildDHCPACK(PhysicalAddress chaddr, DhcpOption55 dhcpoption55, DhcpLeases dhcplease) { DhcpLeaseItem item = dhcplease.GetItem(chaddr); // 必須 this.dhcpoptions_.Add(new DhcpOption53(DhcpPacket.MessageType.DHCPACK)); this.dhcpoptions_.Add(new DhcpOption(54, item.server_identifier_)); this.dhcpoptions_.Add(new DhcpOption(51, item.lease_time_)); // 任意 if (dhcpoption55.parameter_request_list_ != null) { foreach (byte b in dhcpoption55.parameter_request_list_) { switch (b) { case 1: this.dhcpoptions_.Add(new DhcpOption(1, item.subnet_mask_)); break; case 3: this.dhcpoptions_.Add(new DhcpOption(3, item.router_)); break; case 6: this.dhcpoptions_.Add(new DhcpOption(6, item.domain_name_server_)); break; case 58: this.dhcpoptions_.Add(new DhcpOption(58, item.renewal_time_)); break; case 59: this.dhcpoptions_.Add(new DhcpOption(59, item.rebinding_time_)); break; default: break; } } } // 必須(最後必ず) this.dhcpoptions_.Add(new DhcpOption(255)); }
// 解析 public static DhcpOption Parse(byte[] optionBytes, ref int pos) { // Pad Optionをスキップ while ((pos < optionBytes.Length) && (optionBytes[pos] == CODE_PAD_OPTION)) { pos++; } if (pos >= optionBytes.Length) { return(null); } // 生成 int code = optionBytes[pos++]; DhcpOption dhcpoption = null; switch (code) { case 53: dhcpoption = new DhcpOption53(); break; case 55: dhcpoption = new DhcpOption55(); break; default: dhcpoption = new DhcpOption(); break; } dhcpoption._Code = code; // End Option if (dhcpoption._Code == CODE_END_OPTION) { dhcpoption._Len = 0; dhcpoption._bytes = null; return(dhcpoption); } dhcpoption._Len = optionBytes[pos++]; if (pos + dhcpoption._Len > optionBytes.Length) { return(null); } dhcpoption._bytes = optionBytes.Skip(pos).Take(dhcpoption._Len).ToArray(); pos += dhcpoption._Len; // 解析 dhcpoption.Analyze(); return(dhcpoption); }
// コンストラクタ // 受信パケットの Parameter Request List ベース public DhcpOptions(DhcpPacket.MessageType message_type, PhysicalAddress chaddr, DhcpOption55 dhcpoption55, DhcpLeases dhcplease) : this() { if (message_type == DhcpPacket.MessageType.DHCPOFFER) { BuildDHCPOFFER(chaddr, dhcpoption55, dhcplease); } if (message_type == DhcpPacket.MessageType.DHCPACK) { BuildDHCPACK(chaddr, dhcpoption55, dhcplease); } }