Commit c7aeb4be authored by Mukund Sivaraman's avatar Mukund Sivaraman

[2749] Update rest of tree to use the modified io_utilities.h API

parent d5843329
......@@ -604,9 +604,10 @@ Dhcpv6Srv::generateServerID() {
seconds -= DUID_TIME_EPOCH;
OptionBuffer srvid(8 + iface->getMacLen());
writeUint16(DUID::DUID_LLT, &srvid[0]);
writeUint16(HWTYPE_ETHERNET, &srvid[2]);
writeUint32(static_cast<uint32_t>(seconds), &srvid[4]);
writeUint16(DUID::DUID_LLT, &srvid[0], srvid.size());
writeUint16(HWTYPE_ETHERNET, &srvid[2], srvid.size() - 2);
writeUint32(static_cast<uint32_t>(seconds), &srvid[4],
srvid.size() - 4);
memcpy(&srvid[0] + 8, iface->getMac(), iface->getMacLen());
serverid_ = OptionPtr(new Option(Option::V6, D6O_SERVERID,
......@@ -620,8 +621,8 @@ Dhcpv6Srv::generateServerID() {
// See Section 9.3 of RFC3315 for details.
OptionBuffer srvid(12);
writeUint16(DUID::DUID_EN, &srvid[0]);
writeUint32(ENTERPRISE_ID_ISC, &srvid[2]);
writeUint16(DUID::DUID_EN, &srvid[0], srvid.size());
writeUint32(ENTERPRISE_ID_ISC, &srvid[2], srvid.size() - 2);
// Length of the identifier is company specific. I hereby declare
// ISC "standard" of 6 bytes long pseudo-random numbers.
......@@ -2344,10 +2345,10 @@ Dhcpv6Srv::unpackOptions(const OptionBuffer& buf,
// The buffer being read comprises a set of options, each starting with
// a two-byte type code and a two-byte length field.
while (offset + 4 <= length) {
uint16_t opt_type = isc::util::readUint16(&buf[offset]);
uint16_t opt_type = isc::util::readUint16(&buf[offset], 2);
offset += 2;
uint16_t opt_len = isc::util::readUint16(&buf[offset]);
uint16_t opt_len = isc::util::readUint16(&buf[offset], 2);
offset += 2;
if (offset + opt_len > length) {
......
......@@ -162,7 +162,7 @@ struct IOFetchData {
// we sent.
bool responseOK() {
return (*remote_snd == *remote_rcv && cumulative >= 2 &&
readUint16(received->getData()) == qid);
readUint16(received->getData(), received->getLength()) == qid);
}
};
......
......@@ -280,7 +280,7 @@ public:
cumulative_ += length;
bool complete = false;
if (cumulative_ > 2) {
uint16_t dns_length = readUint16(receive_buffer_);
uint16_t dns_length = readUint16(receive_buffer_, sizeof (receive_buffer_));
complete = ((dns_length + 2) == cumulative_);
}
......@@ -310,7 +310,10 @@ public:
send_buffer_.clear();
send_buffer_.push_back(0);
send_buffer_.push_back(0);
writeUint16(return_data_.size(), &send_buffer_[0]);
// send_buffer_.capacity() seems more logical below, but the
// code above fills in the first two bytes and size() becomes 2
// (sizeof uint16_t).
writeUint16(return_data_.size(), &send_buffer_[0], send_buffer_.size());
copy(return_data_.begin(), return_data_.end(), back_inserter(send_buffer_));
if (return_data_.size() >= 2) {
send_buffer_[2] = qid_0;
......
......@@ -358,7 +358,7 @@ TCPSocket<C>::processReceivedData(const void* staging, size_t length,
}
// Have enough data to interpret the packet count, so do so now.
expected = isc::util::readUint16(data);
expected = isc::util::readUint16(data, cumulative);
// We have two bytes less of data to process. Point to the start of the
// data and adjust the packet size. Note that at this point,
......
......@@ -227,7 +227,7 @@ serverRead(tcp::socket& socket, TCPCallback& server_cb) {
// If we have read at least two bytes, we can work out how much we
// should be reading.
if (server_cb.cumulative() >= 2) {
server_cb.expected() = readUint16(server_cb.data());
server_cb.expected() = readUint16(server_cb.data(), server_cb.length());
if ((server_cb.expected() + 2) == server_cb.cumulative()) {
// Amount of data read from socket equals the size of the
......@@ -261,7 +261,7 @@ TEST(TCPSocket, processReceivedData) {
}
// Check that the method will handle various receive sizes.
writeUint16(PACKET_SIZE, inbuff);
writeUint16(PACKET_SIZE, inbuff, sizeof (inbuff));
cumulative = 0;
offset = 0;
......@@ -408,7 +408,7 @@ TEST(TCPSocket, SequenceTest) {
server_cb.length() = 0;
server_cb.cumulative() = 0;
writeUint16(sizeof(INBOUND_DATA), server_cb.data());
writeUint16(sizeof(INBOUND_DATA), server_cb.data(), 2);
copy(INBOUND_DATA, (INBOUND_DATA + sizeof(INBOUND_DATA) - 1),
(server_cb.data() + 2));
server_socket.async_send(asio::buffer(server_cb.data(),
......
......@@ -188,7 +188,7 @@ TEST(UDPSocket, processReceivedData) {
// two bytes of the buffer.
uint16_t count = 0;
for (uint32_t i = 0; i < (2 << 16); ++i, ++count) {
writeUint16(count, inbuff);
writeUint16(count, inbuff, sizeof (inbuff));
// Set some random values
cumulative = 5;
......
......@@ -223,10 +223,10 @@ size_t LibDHCP::unpackOptions6(const OptionBuffer& buf,
// The buffer being read comprises a set of options, each starting with
// a two-byte type code and a two-byte length field.
while (offset + 4 <= length) {
uint16_t opt_type = isc::util::readUint16(&buf[offset]);
uint16_t opt_type = isc::util::readUint16(&buf[offset], 2);
offset += 2;
uint16_t opt_len = isc::util::readUint16(&buf[offset]);
uint16_t opt_len = isc::util::readUint16(&buf[offset], 2);
offset += 2;
if (offset + opt_len > length) {
......@@ -405,10 +405,10 @@ size_t LibDHCP::unpackVendorOptions6(const uint32_t vendor_id,
// The buffer being read comprises a set of options, each starting with
// a two-byte type code and a two-byte length field.
while (offset + 4 <= length) {
uint16_t opt_type = isc::util::readUint16(&buf[offset]);
uint16_t opt_type = isc::util::readUint16(&buf[offset], 2);
offset += 2;
uint16_t opt_len = isc::util::readUint16(&buf[offset]);
uint16_t opt_len = isc::util::readUint16(&buf[offset], 2);
offset += 2;
if (offset + opt_len > length) {
......
......@@ -255,7 +255,7 @@ uint16_t Option::getUint16() {
<< " that has size " << data_.size());
}
return ( readUint16(&data_[0]) );
return (readUint16(&data_[0], data_.size()));
}
uint32_t Option::getUint32() {
......@@ -263,7 +263,7 @@ uint32_t Option::getUint32() {
isc_throw(OutOfRange, "Attempt to read uint32 from option " << type_
<< " that has size " << data_.size());
}
return ( readUint32(&data_[0]) );
return (readUint32(&data_[0], data_.size()));
}
void Option::setUint8(uint8_t value) {
......@@ -273,12 +273,12 @@ void Option::setUint8(uint8_t value) {
void Option::setUint16(uint16_t value) {
data_.resize(2);
writeUint16(value, &data_[0]);
writeUint16(value, &data_[0], data_.size());
}
void Option::setUint32(uint32_t value) {
data_.resize(4);
writeUint32(value, &data_[0]);
writeUint32(value, &data_[0], data_.size());
}
bool Option::equal(const OptionPtr& other) const {
......
......@@ -53,7 +53,7 @@ Option4AddrLst::Option4AddrLst(uint8_t type, OptionBufferConstIter first,
while (first != last) {
const uint8_t* ptr = &(*first);
addAddress(IOAddress(readUint32(ptr)));
addAddress(IOAddress(readUint32(ptr, distance(first, last))));
first += V4ADDRESS_LEN;
}
}
......
......@@ -72,12 +72,12 @@ void Option6IA::unpack(OptionBufferConstIter begin,
if (distance(begin, end) < OPTION6_IA_LEN) {
isc_throw(OutOfRange, "Option " << type_ << " truncated");
}
iaid_ = readUint32( &(*begin) );
iaid_ = readUint32(&(*begin), distance(begin, end));
begin += sizeof(uint32_t);
t1_ = readUint32( &(*begin) );
t1_ = readUint32(&(*begin), distance(begin, end));
begin += sizeof(uint32_t);
t2_ = readUint32( &(*begin) );
t2_ = readUint32(&(*begin), distance(begin, end));
begin += sizeof(uint32_t);
unpackOptions(OptionBuffer(begin, end));
......
......@@ -79,10 +79,10 @@ void Option6IAAddr::unpack(OptionBuffer::const_iterator begin,
addr_ = IOAddress::fromBytes(AF_INET6, &(*begin));
begin += V6ADDRESS_LEN;
preferred_ = readUint32( &(*begin) );
preferred_ = readUint32(&(*begin), distance(begin, end));
begin += sizeof(uint32_t);
valid_ = readUint32( &(*begin) );
valid_ = readUint32(&(*begin), distance(begin, end));
begin += sizeof(uint32_t);
unpackOptions(OptionBuffer(begin, end));
......
......@@ -76,10 +76,10 @@ void Option6IAPrefix::unpack(OptionBuffer::const_iterator begin,
isc_throw(OutOfRange, "Option " << type_ << " truncated");
}
preferred_ = readUint32( &(*begin) );
preferred_ = readUint32(&(*begin), distance(begin, end));
begin += sizeof(uint32_t);
valid_ = readUint32( &(*begin) );
valid_ = readUint32(&(*begin), distance(begin, end));
begin += sizeof(uint32_t);
prefix_len_ = *begin;
......
......@@ -298,12 +298,12 @@ public:
case 2:
// Calling readUint16 works either for unsigned
// or signed types.
value = isc::util::readUint16(&(*buf.begin()));
value = isc::util::readUint16(&(*buf.begin()), buf.size());
break;
case 4:
// Calling readUint32 works either for unsigned
// or signed types.
value = isc::util::readUint32(&(*buf.begin()));
value = isc::util::readUint32(&(*buf.begin()), buf.size());
break;
default:
// This should not happen because we made checks on data types
......@@ -331,11 +331,11 @@ public:
break;
case 2:
buf.resize(buf.size() + 2);
isc::util::writeUint16(static_cast<uint16_t>(value), &buf[buf.size() - 2]);
isc::util::writeUint16(static_cast<uint16_t>(value), &buf[buf.size() - 2], 2);
break;
case 4:
buf.resize(buf.size() + 4);
isc::util::writeUint32(static_cast<uint32_t>(value), &buf[buf.size() - 4]);
isc::util::writeUint32(static_cast<uint32_t>(value), &buf[buf.size() - 4], 4);
break;
default:
// The cases above cover whole range of possible data lengths because
......
......@@ -142,10 +142,12 @@ public:
value_ = *begin;
break;
case 2:
value_ = isc::util::readUint16(&(*begin));
value_ = isc::util::readUint16(&(*begin),
std::distance(begin, end));
break;
case 4:
value_ = isc::util::readUint32(&(*begin));
value_ = isc::util::readUint32(&(*begin),
std::distance(begin, end));
break;
default:
isc_throw(dhcp::InvalidDataType, "non-integer type");
......
......@@ -201,10 +201,12 @@ public:
values_.push_back(*begin);
break;
case 2:
values_.push_back(isc::util::readUint16(&(*begin)));
values_.push_back(isc::util::readUint16(&(*begin),
std::distance(begin, end)));
break;
case 4:
values_.push_back(isc::util::readUint32(&(*begin)));
values_.push_back(isc::util::readUint32(&(*begin),
std::distance(begin, end)));
break;
default:
isc_throw(dhcp::InvalidDataType, "non-integer type");
......
......@@ -54,7 +54,7 @@ void OptionVendor::unpack(OptionBufferConstIter begin,
<< ", length=" << distance(begin, end));
}
vendor_id_ = isc::util::readUint32(&(*begin));
vendor_id_ = isc::util::readUint32(&(*begin), distance(begin, end));
OptionBuffer vendor_buffer(begin +4, end);
......
......@@ -462,7 +462,8 @@ public:
tcp_cumulative_ += length;
bool complete = false;
if (tcp_cumulative_ > 2) {
uint16_t dns_length = readUint16(tcp_receive_buffer_);
uint16_t dns_length = readUint16(tcp_receive_buffer_,
sizeof (tcp_receive_buffer_));
complete = ((dns_length + 2) == tcp_cumulative_);
}
......
......@@ -336,7 +336,8 @@ public:
tcp_cumulative_ += length;
bool complete = false;
if (tcp_cumulative_ > 2) {
uint16_t dns_length = readUint16(tcp_receive_buffer_);
uint16_t dns_length = readUint16(tcp_receive_buffer_,
sizeof (tcp_receive_buffer_));
complete = ((dns_length + 2) == tcp_cumulative_);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment