34 const void *extra_data,
35 const size_t extra_data_size,
37 const uint16_t seq_num,
38 const size_t total_size,
39 std::string *log_info)
41 const unsigned int data_size = std::max(
int(extra_data_size),
int(total_size) -
int(
sizeof(
ICMPv4)));
44 *log_info =
"PING4 " + src.
to_string() +
" -> " + dest.
to_string() +
" id=" + std::to_string(
id) +
" seq_num=" + std::to_string(seq_num) +
" data_size=" + std::to_string(data_size);
46 const auto total_length = clamp_to_typerange<uint16_t>(
sizeof(
ICMPv4) + data_size);
71 std::uint8_t *data = b +
sizeof(
ICMPv4);
72 for (
size_t i = 0; i < data_size; ++i)
73 data[i] = (std::uint8_t)i;
76 std::memcpy(data, extra_data, extra_data_size);
87 std::string *log_info)
92 *log_info =
"Invalid ECHO4_REQUEST";
98 const std::uint16_t old_type_code = icmp->
type_code;
const T * c_data() const
Returns a const pointer to the start of the buffer.
T * write_alloc(const size_t size)
Allocate space for writing data to the buffer.
size_t size() const
Returns the size of the buffer in T objects.
static Addr from_uint32_net(const base_type addr)
std::uint32_t to_uint32_net() const
std::string to_string() const
std::uint32_t cunfold(const std::uint16_t sum)
std::uint16_t cfold(const std::uint32_t sum)
std::uint32_t diff2(const std::uint16_t old, const std::uint16_t new_, const std::uint32_t oldsum)
std::uint16_t checksum(const void *data, const size_t size)
void generate_echo_request(Buffer &buf, const IPv4::Addr &src, const IPv4::Addr &dest, const void *extra_data, const size_t extra_data_size, const uint16_t id, const uint16_t seq_num, const size_t total_size, std::string *log_info)
void generate_echo_reply(Buffer &buf, std::string *log_info)
OutT clamp_to_typerange(InT inVal)
Clamps the input value to the legal range for the output type.