42 #ifndef _DWMIPV4TCPPAYLOAD_HH_ 43 #define _DWMIPV4TCPPAYLOAD_HH_ 108 std::pair<uint16_t,const uint8_t *>
Payload()
const;
119 uint32_t
Sum()
const;
126 template <
typename T>
130 if (_payload.first) {
131 std::istringstream is(std::string((
const char *)_payload.second,
143 template <
typename T>
149 uint16_t maxPayloadLen = 65535 - (20 + 8);
151 if (payloadLen <= maxPayloadLen) {
152 std::ostringstream os;
154 _payload.first = payloadLen;
155 _payload.second = (uint8_t *)calloc(1, _payload.first);
156 assert(_payload.second);
157 memcpy(_payload.second, os.str().c_str(), _payload.first);
172 std::istream &
Read(std::istream & is, uint16_t len);
177 std::ostream &
Write(std::ostream & os)
const;
183 ssize_t
Read(
int fd, uint16_t len);
189 ssize_t
Write(
int fd)
const;
195 size_t Read(FILE *f, uint16_t len);
201 size_t Write(FILE *f)
const;
207 int Read(gzFile gzf, uint16_t len);
213 int Write(gzFile gzf)
const;
219 int BZRead(BZFILE *bzf, uint16_t len);
225 int BZWrite(BZFILE *bzf)
const;
234 std::pair<uint16_t, uint8_t *> _payload;
238 void Allocate(uint16_t len);
243 #endif // _DWMIPV4TCPPAYLOAD_HH_ Ipv4TcpPayload()
Constructor.
This class is a pure virtual class, defining an interface for classes that can write their contents t...
Definition: DwmGZWritable.hh:57
~Ipv4TcpPayload()
Destructor.
Dwm::Writable pure virtual class definition.
std::istream & Read(std::istream &is, uint16_t len)
Reads len bytes of the payload from the given istream is.
bool SetPayload(const T &payload)
Sets the payload to payload.
Definition: DwmIpv4TcpPayload.hh:144
int BZRead(BZFILE *bzf, uint16_t len)
Reads len bytes of the payload from the given BZFILE bzf.
uint32_t StreamedLength() const
Returns the number of bytes that would be written if we called one of the Write() members...
Encapsulates a TCP payload.
Definition: DwmIpv4TcpPayload.hh:68
std::ostream & Write(std::ostream &os) const
Writes the payload to the given ostream os.
static std::ostream & Write(std::ostream &os, char c)
Writes c to os. Returns os.
std::pair< uint16_t, const uint8_t * > Payload() const
Returns a shallow copy of the payload.
Dwm::BZ2Writable pure virtual class definition.
std::string ToString() const
Returns the payload as a string.
static std::istream & Read(std::istream &is, char &c)
Reads c from is. Returns is.
Definition: DwmBZ2IO.hh:67
Dwm::IO class definition.
This class defines an interface for classes that can write their contents to an ostream, file descriptor or FILE pointer.
Definition: DwmWritable.hh:58
static uint32_t StreamedLength(char c)
Returns the number of bytes that would be written if we called Write() for a char.
Definition: DwmIO.hh:92
This class is a pure virtual class, defining an interface for classes that can write their contents t...
Definition: DwmBZ2Writable.hh:57
Dwm::GZWritable pure virtual class definition.
uint32_t Sum() const
Returns the IP sum of the payload, which can be used as part of TCP checksum computation.
void Clear()
Clears the payload.
int BZWrite(BZFILE *bzf) const
Writes the payload to the given BZFILE bzf.
bool GetPayload(T &payload) const
Copies the payload into payload.
Definition: DwmIpv4TcpPayload.hh:127