mirror of
https://github.com/genodelabs/genode.git
synced 2025-02-20 17:52:52 +00:00
net: write accessors for Ipv4_packet
Also adds header-checksum calculation function. Fixes #1915
This commit is contained in:
parent
bed870ead4
commit
27a73b89f0
@ -60,6 +60,8 @@ class Net::Ipv4_packet
|
||||
|
||||
static Ipv4_address ip_from_string(const char *ip);
|
||||
|
||||
static Genode::uint16_t calculate_checksum(Ipv4_packet const &packet);
|
||||
|
||||
private:
|
||||
|
||||
/************************
|
||||
@ -161,6 +163,20 @@ class Net::Ipv4_packet
|
||||
template <typename T> T * data() { return (T *)(_data); }
|
||||
template <typename T> T const * data() const { return (T const *)(_data); }
|
||||
|
||||
/********************************
|
||||
** IPv4 field write-accessors **
|
||||
********************************/
|
||||
|
||||
void version(Genode::size_t version) { _version = version; }
|
||||
void header_length(Genode::size_t len) { _header_length = len; }
|
||||
|
||||
void total_length(Genode::uint16_t len) { _total_length = host_to_big_endian(len); }
|
||||
void time_to_live(Genode::uint8_t ttl) { _time_to_live = ttl; }
|
||||
|
||||
void checksum(Genode::uint16_t checksum) { _header_checksum = host_to_big_endian(checksum); }
|
||||
|
||||
void dst(Ipv4_address ip) { ip.copy(&_dst_addr); }
|
||||
void src(Ipv4_address ip) { ip.copy(&_src_addr); }
|
||||
|
||||
/***************
|
||||
** Operators **
|
||||
|
@ -62,6 +62,21 @@ Ipv4_packet::Ipv4_address Ipv4_packet::ip_from_string(const char *ip)
|
||||
return ip_addr;
|
||||
}
|
||||
|
||||
Genode::uint16_t Ipv4_packet::calculate_checksum(Ipv4_packet const &packet)
|
||||
{
|
||||
Genode::uint16_t const *data = packet.header<Genode::uint16_t>();
|
||||
Genode::uint32_t const sum = host_to_big_endian(data[0])
|
||||
+ host_to_big_endian(data[1])
|
||||
+ host_to_big_endian(data[2])
|
||||
+ host_to_big_endian(data[3])
|
||||
+ host_to_big_endian(data[4])
|
||||
+ host_to_big_endian(data[6])
|
||||
+ host_to_big_endian(data[7])
|
||||
+ host_to_big_endian(data[8])
|
||||
+ host_to_big_endian(data[9]);
|
||||
return ~((0xFFFF & sum) + (sum >> 16));
|
||||
}
|
||||
|
||||
|
||||
const Ipv4_packet::Ipv4_address Ipv4_packet::CURRENT((Genode::uint8_t)0x00);
|
||||
const Ipv4_packet::Ipv4_address Ipv4_packet::BROADCAST((Genode::uint8_t)0xFF);
|
||||
|
Loading…
x
Reference in New Issue
Block a user