Sponge
CS144's user-space TCP library
libsponge
tcp_helpers
ethernet_frame.cc
Go to the documentation of this file.
1
#include "
ethernet_frame.hh
"
2
3
#include "
parser.hh
"
4
#include "
util.hh
"
5
6
#include <stdexcept>
7
#include <string>
8
9
using namespace
std
;
10
11
ParseResult
EthernetFrame::parse
(
const
Buffer
buffer
) {
12
NetParser
p{
buffer
};
13
_header.parse(p);
14
_payload = p.buffer();
15
16
return
p.get_error();
17
}
18
19
BufferList
EthernetFrame::serialize
()
const
{
20
BufferList
ret;
21
ret.
append
(_header.serialize());
22
ret.
append
(_payload);
23
return
ret;
24
}
util.hh
BufferList::append
void append(const BufferList &other)
Append a BufferList.
Definition:
buffer.cc:15
BufferList
A reference-counted discontiguous string that can discard bytes from the front.
Definition:
buffer.hh:56
buffer
std::string buffer
Definition:
parser_example.cc:7
Buffer
A reference-counted read-only string that can discard bytes from the front.
Definition:
buffer.hh:14
ParseResult
ParseResult
The result of parsing or unparsing an IP datagram, TCP segment, Ethernet frame, or ARP message.
Definition:
parser.hh:12
EthernetFrame::parse
ParseResult parse(const Buffer buffer)
Parse the frame from a string.
Definition:
ethernet_frame.cc:11
NetParser
Definition:
parser.hh:25
std
ethernet_frame.hh
EthernetFrame::serialize
BufferList serialize() const
Serialize the frame to a string.
Definition:
ethernet_frame.cc:19
parser.hh
Generated by
1.8.17