Whisper Library
|
Represents a udp packet. More...
Public Member Functions | |
UdpPacket () | |
Creates an empty UdpPacket. | |
UdpPacket (std::vector< bool > content) | |
Creates an UdpPacket with given content. More... | |
unsigned short | sourcePort () const |
unsigned short | destinationPort () const |
unsigned short | length () const |
unsigned short | checksum () const |
std::vector< char > | data () const |
std::vector< bool > | packet () const |
void | setSourcePort (unsigned short value) |
void | setDestinationPort (unsigned short value) |
void | setLength (unsigned short value) |
void | setChecksum (unsigned short value) |
void | setData (std::vector< char > data) |
void | setPacket (std::vector< bool > packet) |
string | toString () |
![]() | |
GenericPacket () | |
Creates a GenericPacket. | |
GenericPacket (vector< bool > content) | |
Creates a GenericPacket with the given content. More... | |
void | setPacket (vector< bool > content) |
Sets the content of the packet. More... | |
vector< bool > | packet () const |
Private Member Functions | |
unsigned short | decode (int start, int end) const |
returns the headerfield between start and end More... | |
void | encode (int start, int end, unsigned short value) |
writes the given value in the headerfield beetween start and end More... | |
Private Attributes | |
unsigned char | m_head [8] |
Holds the header as unsigned characters. | |
std::vector< char > | m_data |
Holds the data as characters. | |
Friends | |
std::ostream & | operator<< (std::ostream &ostream, const UdpPacket &packet) |
Represents a udp packet.
A UdpPacket represents a udp packet, that means the udp header an the data payload. It can be used to store and access all fields and it offers a stream operator to write it in std::ostream.
whisper_library::UdpPacket::UdpPacket | ( | std::vector< bool > | content | ) |
Creates an UdpPacket with given content.
content | the bits that are used to fill the packet |
unsigned short whisper_library::UdpPacket::checksum | ( | ) | const |
std::vector< char > whisper_library::UdpPacket::data | ( | ) | const |
|
private |
returns the headerfield between start and end
The bytes of the m_head between start and end get interpreted as unsigned short and returned. Because unsigned short only holds two byte, start and end should be succesive.
start | the index of the first byte |
end | the index of the last byte |
unsigned short whisper_library::UdpPacket::destinationPort | ( | ) | const |
|
private |
writes the given value in the headerfield beetween start and end
The two bytes of value are written in m_head at the indices start and end. Start and end should be succesive.
start | the index for the first half of value |
end | the index for the seconde halt of value |
value | the two bytes that are written in m_head |
unsigned short whisper_library::UdpPacket::length | ( | ) | const |
std::vector< bool > whisper_library::UdpPacket::packet | ( | ) | const |
void whisper_library::UdpPacket::setChecksum | ( | unsigned short | value | ) |
sets the checksum (byte 7 and 8)
value | the new checksum |
void whisper_library::UdpPacket::setData | ( | std::vector< char > | data | ) |
sets the data payload
data | the new data payload |
void whisper_library::UdpPacket::setDestinationPort | ( | unsigned short | value | ) |
sets the destination port (byte 3 and 4)
value | the new destination port |
void whisper_library::UdpPacket::setLength | ( | unsigned short | value | ) |
sets the packet length (byte 5 and 6)
value | the new packet length |
void whisper_library::UdpPacket::setPacket | ( | std::vector< bool > | packet | ) |
sets the whole packet
packet | the new packet as bits |
void whisper_library::UdpPacket::setSourcePort | ( | unsigned short | value | ) |
sets the source port (byte 1 and 2)
value | the new source port |
unsigned short whisper_library::UdpPacket::sourcePort | ( | ) | const |
string whisper_library::UdpPacket::toString | ( | ) |
Creates a string that contains all header fields.
|
friend |
streamoperator to write the whole packet to a std::ostream