62 std::memset(
data, 0, ETH_ADDR_LEN);
67 for (
int i = 0;
i < ETH_ADDR_LEN; ++
i)
73 for (
int i = 0;
i < ETH_ADDR_LEN; ++
i)
101 int bytes[ETH_ADDR_LEN == 6 ? ETH_ADDR_LEN : -1];
102 if (sscanf(
addr.c_str(),
"%x:%x:%x:%x:%x:%x", &
bytes[0], &
bytes[1],
104 std::memset(
data, 0xff, ETH_ADDR_LEN);
108 for (
int i = 0;
i < ETH_ADDR_LEN; ++
i) {
110 std::memset(
data, 0xff, ETH_ADDR_LEN);
121 std::stringstream stream;
129 return !std::memcmp(left.
bytes(), right.
bytes(), ETH_ADDR_LEN);
135 const uint8_t *
a =
ea.addr();
136 ccprintf(stream,
"%x:%x:%x:%x:%x:%x",
a[0],
a[1],
a[2],
a[3],
a[4],
a[5]);
143 std::stringstream stream;
151 return left.
ip() == right.
ip();
157 uint32_t ip =
ia.ip();
159 (uint8_t)(ip >> 24), (uint8_t)(ip >> 16),
160 (uint8_t)(ip >> 8), (uint8_t)(ip >> 0));
167 std::stringstream stream;
175 return (left.
ip() == right.
ip()) &&
189 std::stringstream stream;
197 return (left.
ip() == right.
ip()) && (left.
port() == right.
port());
211 return ip_cksum_carry(
sum);
217 int tcplen = ip->len() - ip->hlen();
218 int sum = ip_cksum_add(ip->payload(), tcplen, 0);
219 sum = ip_cksum_add(&ip->ip_src, 8,
sum);
220 sum += htons(ip->ip_p + tcplen);
221 return ip_cksum_carry(
sum);
227 int tcplen =
ip6->plen() -
ip6->extensionLength();
228 int sum = ip_cksum_add(
ip6->payload(), tcplen, 0);
230 sum += htons(
ip6->proto() + tcplen);
231 return ip_cksum_carry(
sum);
237 if (
IpPtr(tcp.packet())) {
239 }
else if (
Ip6Ptr(tcp.packet())) {
242 panic(
"Unrecognized IP packet format");
256 panic(
"Unrecognized IP packet format");
266 const uint8_t *
data =
bytes() +
sizeof(
struct ip_hdr);
267 int all =
hlen() -
sizeof(
struct ip_hdr);
286ip6Extension(uint8_t nxt)
288 return nxt == IP_PROTO_HOPOPTS || nxt == IP_PROTO_ROUTING ||
289 nxt == IP_PROTO_FRAGMENT || nxt == IP_PROTO_AH ||
290 nxt == IP_PROTO_ESP || nxt == IP_PROTO_DSTOPTS;
301 const uint8_t *
data =
bytes() + IP6_HDR_LEN;
302 uint8_t
nxt = ip6_nxt;
304 [[maybe_unused]]
int all =
plen();
306 while (ip6Extension(
nxt)) {
324 const uint8_t *
data =
bytes() + IP6_HDR_LEN;
325 uint8_t
nxt = ip6_nxt;
327 [[maybe_unused]]
int all =
plen();
329 while (ip6Extension(
nxt)) {
331 if (
nxt == ext_type) {
340 return (
const Ip6Opt*)opt;
350 const uint8_t *
data =
bytes() + IP6_HDR_LEN;
351 uint8_t
nxt = ip6_nxt;
352 [[maybe_unused]]
int all =
plen();
354 while (ip6Extension(
nxt)) {
369 const uint8_t *
data =
bytes() +
sizeof(
struct tcp_hdr);
370 int all =
off() -
sizeof(
struct tcp_hdr);
393 split_point = ip.pstart();
397 split_point = tcp.pstart();
401 split_point = udp.
pstart();
403 split_point =
ip6.pstart();
407 split_point = tcp.pstart();
410 split_point = udp.
pstart();
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
uint16_t cksum(const IpPtr &ptr)
uint16_t __tu_cksum6(const Ip6Ptr &ip6)
int hsplit(const EthPacketPtr &ptr)
const EthPacketPtr packet() const
uint16_t __tu_cksum(const IpPtr &ip)
std::string string() const
const uint8_t * addr() const
bool operator==(const EthAddr &left, const EthAddr &right)
const uint8_t * bytes() const
std::string string() const
std::ostream & operator<<(std::ostream &stream, const EthAddr &ea)
const EthAddr & operator=(const eth_addr &ea)
#define panic(...)
This implements a cprintf based panic() function.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
void ccprintf(cp::Print &print)
std::shared_ptr< EthPacketData > EthPacketPtr
void parse(const std::string &addr)
const Ip6Opt * getExt(uint8_t ext) const
const uint8_t * bytes() const
int extensionLength() const
const uint8_t * bytes() const
bool options(std::vector< const IpOpt * > &vec) const
std::string string() const
std::string string() const
bool options(std::vector< const TcpOpt * > &vec) const
const uint8_t * bytes() const