From: Tomek Mrugalski Date: Fri, 19 Aug 2016 15:21:52 +0000 (+0200) Subject: [4483] Several existing instances converted to fromUint32 X-Git-Tag: trac4631_base~15^2~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83ddd93865d5fcf62516d3e7703e8bc380ba5dc1;p=thirdparty%2Fkea.git [4483] Several existing instances converted to fromUint32 --- diff --git a/src/lib/eval/token.cc b/src/lib/eval/token.cc index e7224618d6..8d8098da0e 100644 --- a/src/lib/eval/token.cc +++ b/src/lib/eval/token.cc @@ -201,11 +201,12 @@ TokenPkt::evaluate(Pkt& pkt, ValueStack& values) { string value; vector binary; string type_str; - uint32_t len; bool is_binary = true; + bool print_hex = true; switch (type_) { case IFACE: is_binary = false; + print_hex = false; value = pkt.getIface(); type_str = "iface"; break; @@ -222,9 +223,8 @@ TokenPkt::evaluate(Pkt& pkt, ValueStack& values) { // (with UDP transport it fits in 16 bits) // the len() method is not const because of DHCPv6 relays. // We assume here it has no bad side effects... - len = static_cast(const_cast(pkt).len()); - binary.resize(sizeof(uint32_t)); - static_cast(writeUint32(len, &binary[0], binary.size())); + value = EvalContext::fromUint32(static_cast(const_cast(pkt).len())); + is_binary = false; type_str = "len"; break; @@ -244,13 +244,14 @@ TokenPkt::evaluate(Pkt& pkt, ValueStack& values) { // Log what we pushed LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_PKT) .arg(type_str) - .arg(is_binary ? toHex(value) : value); + .arg(print_hex ? toHex(value) : value); } void TokenPkt4::evaluate(Pkt& pkt, ValueStack& values) { vector binary; + string value; string type_str; try { // Check if it's a Pkt4. If it's not, the dynamic_cast will throw @@ -293,19 +294,13 @@ TokenPkt4::evaluate(Pkt& pkt, ValueStack& values) { case HLEN: // Pad the uint8_t field to 4 bytes. - binary.push_back(0); - binary.push_back(0); - binary.push_back(0); - binary.push_back(pkt4.getHlen()); + value = EvalContext::fromUint32(pkt4.getHlen()); type_str = "hlen"; break; case HTYPE: // Pad the uint8_t field to 4 bytes. - binary.push_back(0); - binary.push_back(0); - binary.push_back(0); - binary.push_back(pkt4.getHtype()); + value = EvalContext::fromUint32(pkt4.getHtype()); type_str = "htype"; break; @@ -318,9 +313,8 @@ TokenPkt4::evaluate(Pkt& pkt, ValueStack& values) { isc_throw(EvalTypeError, "Specified packet is not a Pkt4"); } - string value; - value.resize(binary.size()); if (!binary.empty()) { + value.resize(binary.size()); memmove(&value[0], &binary[0], binary.size()); } values.push(value); @@ -334,7 +328,7 @@ TokenPkt4::evaluate(Pkt& pkt, ValueStack& values) { void TokenPkt6::evaluate(Pkt& pkt, ValueStack& values) { - vector binary; + string value; string type_str; try { // Check if it's a Pkt6. If it's not the dynamic_cast will throw @@ -345,20 +339,13 @@ TokenPkt6::evaluate(Pkt& pkt, ValueStack& values) { switch (type_) { case MSGTYPE: { // msg type is an uint8_t integer. We want a 4 byte string so 0 pad. - binary.push_back(0); - binary.push_back(0); - binary.push_back(0); - binary.push_back(pkt6.getType()); + value = EvalContext::fromUint32(pkt6.getType()); type_str = "msgtype"; break; } case TRANSID: { // transaction id is an uint32_t integer. We want a 4 byte string so copy - uint32_t transid = pkt6.getTransid(); - binary.push_back(transid >> 24); - binary.push_back((transid >> 16) & 0xFF); - binary.push_back((transid >> 8) & 0xFF); - binary.push_back(transid & 0xFF); + value = EvalContext::fromUint32(pkt6.getTransid()); type_str = "transid"; break; } @@ -371,9 +358,6 @@ TokenPkt6::evaluate(Pkt& pkt, ValueStack& values) { isc_throw(EvalTypeError, "Specified packet is not Pkt6"); } - string value; - value.resize(binary.size()); - memmove(&value[0], &binary[0], binary.size()); values.push(value); // Log what we pushed