61 memset(
data, 0, ETH_ADDR_LEN);
64 EthAddr::EthAddr(
const uint8_t
ea[ETH_ADDR_LEN])
66 for (
int i = 0;
i < ETH_ADDR_LEN; ++
i)
70 EthAddr::EthAddr(
const eth_addr &
ea)
72 for (
int i = 0;
i < ETH_ADDR_LEN; ++
i)
76 EthAddr::EthAddr(
const std::string &
addr)
82 EthAddr::operator=(
const eth_addr &
ea)
89 EthAddr::operator=(
const std::string &
addr)
96 EthAddr::parse(
const std::string &
addr)
100 int bytes[ETH_ADDR_LEN == 6 ? ETH_ADDR_LEN : -1];
101 if (sscanf(addr.c_str(),
"%x:%x:%x:%x:%x:%x", &bytes[0], &bytes[1],
102 &bytes[2], &bytes[3], &bytes[4], &bytes[5]) != ETH_ADDR_LEN) {
103 memset(
data, 0xff, ETH_ADDR_LEN);
107 for (
int i = 0;
i < ETH_ADDR_LEN; ++
i) {
108 if (bytes[
i] & ~0xff) {
109 memset(
data, 0xff, ETH_ADDR_LEN);
118 EthAddr::string()
const
128 return !memcmp(left.
bytes(), right.
bytes(), ETH_ADDR_LEN);
134 const uint8_t *
a = ea.
addr();
135 ccprintf(stream,
"%x:%x:%x:%x:%x:%x", a[0], a[1], a[2], a[3], a[4], a[5]);
140 IpAddress::string()
const
150 return left.
ip() == right.
ip();
156 uint32_t
ip = ia.
ip();
158 (uint8_t)(ip >> 24), (uint8_t)(ip >> 16),
159 (uint8_t)(ip >> 8), (uint8_t)(ip >> 0));
164 IpNetmask::string()
const
174 return (left.
ip() == right.
ip()) &&
186 IpWithPort::string()
const
196 return (left.
ip() == right.
ip()) && (left.
port() == right.
port());
210 return ip_cksum_carry(sum);
216 int tcplen = ip->
len() - ip->
hlen();
217 int sum = ip_cksum_add(ip->
payload(), tcplen, 0);
218 sum = ip_cksum_add(&ip->ip_src, 8, sum);
219 sum += htons(ip->ip_p + tcplen);
220 return ip_cksum_carry(sum);
227 int sum = ip_cksum_add(ip6->
payload(), tcplen, 0);
228 sum = ip_cksum_add(ip6->
src(), 32,
sum);
229 sum += htons(ip6->
proto() + tcplen);
230 return ip_cksum_carry(sum);
265 const uint8_t *
data = bytes() +
sizeof(
struct ip_hdr);
266 int all = hlen() -
sizeof(
struct ip_hdr);
281 #define IP6_EXTENSION(nxt) (nxt == IP_PROTO_HOPOPTS) ? true : \
282 (nxt == IP_PROTO_ROUTING) ? true : \
283 (nxt == IP_PROTO_FRAGMENT) ? true : \
284 (nxt == IP_PROTO_AH) ? true : \
285 (nxt == IP_PROTO_ESP) ? true: \
286 (nxt == IP_PROTO_DSTOPTS) ? true : false
292 Ip6Hdr::extensionLength()
const
294 const uint8_t *
data = bytes() + IP6_HDR_LEN;
295 uint8_t nxt = ip6_nxt;
315 Ip6Hdr::getExt(uint8_t ext_type)
const
317 const uint8_t *
data = bytes() + IP6_HDR_LEN;
318 uint8_t nxt = ip6_nxt;
324 if (nxt == ext_type) {
333 return (
const Ip6Opt*)opt;
341 Ip6Hdr::proto()
const
343 const uint8_t *
data = bytes() + IP6_HDR_LEN;
344 uint8_t nxt = ip6_nxt;
362 const uint8_t *
data = bytes() +
sizeof(
struct tcp_hdr);
363 int all = off() -
sizeof(
struct tcp_hdr);
386 split_point = ip.
pstart();
390 split_point = tcp.
pstart();
394 split_point = udp.
pstart();
396 split_point = ip6.
pstart();
400 split_point = tcp.
pstart();
403 split_point = udp.
pstart();
void ccprintf(cp::Print &print)
const uint8_t * payload() const
int hsplit(const EthPacketPtr &ptr)
const EthPacketPtr packet() const
const EthPacketPtr packet() const
uint16_t cksum(const UdpPtr &udp)
const uint8_t * bytes() const
const uint8_t * addr() const
ostream & operator<<(ostream &stream, const IpWithPort &iwp)
std::shared_ptr< EthPacketData > EthPacketPtr
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
const uint8_t * src() const
int extensionLength() const
#define IP6_EXTENSION(nxt)
uint16_t __tu_cksum6(const Ip6Ptr &ip6)
bool operator==(const IpWithPort &left, const IpWithPort &right)
const uint8_t * payload() const
uint16_t __tu_cksum(const IpPtr &ip)
const uint8_t * bytes() const