initOptionSpace(vendor6_defs_[ENTERPRISE_ID_ISC], ISC_V6_DEFS, ISC_V6_DEFS_SIZE);
}
- void initOptionSpace(OptionDefContainer& defs,
+uint32_t
+LibDHCP::optionSpaceToVendorId(const std::string& option_space) {
+ // 8 is a minimal length of "vendor-X" format
+ if ((option_space.size() < 8) || (option_space.substr(0,7) != "vendor-")) {
+ return (0);
+ }
+
+ int64_t check;
+ try {
+ // text after "vendor-", supposedly numbers only
+ std::string x = option_space.substr(7);
+
+ check = boost::lexical_cast<int64_t>(x);
+
+ } catch (const boost::bad_lexical_cast &) {
+ return (0);
+ }
+
+ if ((check < 0) || (check > std::numeric_limits<uint32_t>::max())) {
+ return (0);
+ }
+
+ // value is small enough to fit
+ return (static_cast<uint32_t>(check));
+}
+
+ void initOptionSpace(OptionDefContainerPtr& defs,
const OptionDefParams* params,
size_t params_size) {
- defs.clear();
+ // Container holding vendor options is typically not initialized, as it
+ // is held in map of null pointers. We need to initialize here in this
+ // case.
+ if (!defs) {
+ defs.reset(new OptionDefContainer());
+
+ } else {
+ defs->clear();
+ }
for (size_t i = 0; i < params_size; ++i) {
std::string encapsulates(params[i].encapsulates);