DHCPv6::user_class_type DHCPv6::user_class_type::from_option(const option &opt) { if(opt.data_size() < sizeof(uint16_t)) throw malformed_option(); user_class_type output; output.data = Internals::option2class_option_data<data_type>( opt.data_ptr(), opt.data_size() ); return output; }
PPPoE::vendor_spec_type PPPoE::vendor_spec_type::from_option(const tag& opt) { if (opt.data_size() < sizeof(uint32_t)) { throw malformed_option(); } vendor_spec_type output; InputMemoryStream stream(opt.data_ptr(), opt.data_size()); output.vendor_id = stream.read_be<uint32_t>(); stream.read(output.data, stream.size()); return output; }
DHCPv6::ia_ta_type DHCPv6::ia_ta_type::from_option(const option &opt) { if(opt.data_size() < sizeof(uint32_t)) throw malformed_option(); const uint8_t *ptr = opt.data_ptr() + sizeof(uint32_t); const uint32_t *ptr_32 = (const uint32_t*)opt.data_ptr(); DHCPv6::ia_ta_type output; output.id = Endian::be_to_host(*ptr_32++); output.options.assign(ptr, opt.data_ptr() + opt.data_size()); return output; }
PPPoE::vendor_spec_type PPPoE::vendor_spec_type::from_option(const tag &opt) { if(opt.data_size() < sizeof(uint32_t)) throw malformed_option(); vendor_spec_type output; std::memcpy(&output.vendor_id, opt.data_ptr(), sizeof(uint32_t)); output.vendor_id = Endian::be_to_host(output.vendor_id); output.data.assign( opt.data_ptr() + sizeof(uint32_t), opt.data_ptr() + opt.data_size() ); return output; }
DHCPv6::vendor_info_type DHCPv6::vendor_info_type::from_option(const option &opt) { if(opt.data_size() < sizeof(uint32_t)) throw malformed_option(); vendor_info_type output; std::memcpy(&output.enterprise_number, opt.data_ptr(), sizeof(uint32_t)); output.enterprise_number = Endian::be_to_host(output.enterprise_number); output.data.assign( opt.data_ptr() + sizeof(uint32_t), opt.data_ptr() + opt.data_size() ); return output; }
DHCPv6::status_code_type DHCPv6::status_code_type::from_option(const option &opt) { if(opt.data_size() < sizeof(uint16_t)) throw malformed_option(); status_code_type output; std::memcpy(&output.code, opt.data_ptr(), sizeof(uint16_t)); output.code = Endian::be_to_host(output.code); output.message.assign( opt.data_ptr() + sizeof(uint16_t), opt.data_ptr() + opt.data_size() ); return output; }
DHCPv6::ia_address_type DHCPv6::ia_address_type::from_option(const option &opt) { if(opt.data_size() < sizeof(uint32_t) * 2 + DHCPv6::ipaddress_type::address_size) throw malformed_option(); const uint8_t *ptr = opt.data_ptr() + sizeof(uint32_t) * 2 + ipaddress_type::address_size; const uint32_t *ptr_32 = (const uint32_t*)(opt.data_ptr() + ipaddress_type::address_size); DHCPv6::ia_address_type output; output.address = opt.data_ptr(); output.preferred_lifetime = Endian::be_to_host(*ptr_32++); output.valid_lifetime = Endian::be_to_host(*ptr_32++); output.options.assign(ptr, opt.data_ptr() + opt.data_size()); return output; }
DHCPv6::duid_type DHCPv6::duid_type::from_option(const option &opt) { if(opt.data_size() < sizeof(uint16_t) + 1) throw malformed_option(); uint16_t uint16_t_buffer; std::memcpy(&uint16_t_buffer, opt.data_ptr(), sizeof(uint16_t)); return duid_type( Endian::be_to_host(uint16_t_buffer), serialization_type( opt.data_ptr() + sizeof(uint16_t), opt.data_ptr() + opt.data_size() ) ); }
DHCPv6::vendor_class_type DHCPv6::vendor_class_type::from_option(const option &opt) { if(opt.data_size() < sizeof(uint32_t)) throw malformed_option(); typedef vendor_class_type::class_data_type data_type; vendor_class_type output; std::memcpy(&output.enterprise_number, opt.data_ptr(), sizeof(uint32_t)); output.enterprise_number = Endian::be_to_host(output.enterprise_number); output.vendor_class_data = Internals::option2class_option_data<data_type>( opt.data_ptr() + sizeof(uint32_t), opt.data_size() - sizeof(uint32_t) ); return output; }
DHCPv6::authentication_type DHCPv6::authentication_type::from_option(const option &opt) { if(opt.data_size() < sizeof(uint8_t) * 3 + sizeof(uint64_t)) throw malformed_option(); const uint8_t *ptr = opt.data_ptr(); authentication_type output; output.protocol = *ptr++; output.algorithm = *ptr++; output.rdm = *ptr++; std::memcpy(&output.replay_detection, ptr, sizeof(uint64_t)); output.replay_detection = Endian::be_to_host(output.replay_detection); ptr += sizeof(uint64_t); output.auth_info.assign(ptr, opt.data_ptr() + opt.data_size()); return output; }
RSNInformation RSNInformation::from_option(const PDUOption<uint8_t, Dot11>& opt) { if (opt.data_size() < sizeof(uint16_t) * 2 + sizeof(uint32_t)) { throw malformed_option(); } return RSNInformation(opt.data_ptr(), static_cast<uint32_t>(opt.data_size())); }