Whisper Library
 All Classes Functions Variables Typedefs Enumerations Friends
whisper_library::UdpPacket Class Reference

Represents a udp packet. More...

Inheritance diagram for whisper_library::UdpPacket:
Inheritance graph

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 ()
 
- Public Member Functions inherited from whisper_library::GenericPacket
 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)
 

Detailed Description

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.

Constructor & Destructor Documentation

whisper_library::UdpPacket::UdpPacket ( std::vector< bool >  content)

Creates an UdpPacket with given content.

Parameters
contentthe bits that are used to fill the packet

Member Function Documentation

unsigned short whisper_library::UdpPacket::checksum ( ) const
Returns
the checksum (byte 7 and 8)
std::vector< char > whisper_library::UdpPacket::data ( ) const
Returns
the data payload
unsigned short whisper_library::UdpPacket::decode ( int  start,
int  end 
) 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.

Parameters
startthe index of the first byte
endthe index of the last byte
Returns
the value beetween start and end
unsigned short whisper_library::UdpPacket::destinationPort ( ) const
Returns
the destination port (byte 3 and 4)
void whisper_library::UdpPacket::encode ( int  start,
int  end,
unsigned short  value 
)
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.

Parameters
startthe index for the first half of value
endthe index for the seconde halt of value
valuethe two bytes that are written in m_head
unsigned short whisper_library::UdpPacket::length ( ) const
Returns
the packet length (byte 5 and 6)
std::vector< bool > whisper_library::UdpPacket::packet ( ) const
Returns
the complete packet as std::vector<bool>
void whisper_library::UdpPacket::setChecksum ( unsigned short  value)

sets the checksum (byte 7 and 8)

Parameters
valuethe new checksum
void whisper_library::UdpPacket::setData ( std::vector< char >  data)

sets the data payload

Parameters
datathe new data payload
void whisper_library::UdpPacket::setDestinationPort ( unsigned short  value)

sets the destination port (byte 3 and 4)

Parameters
valuethe new destination port
void whisper_library::UdpPacket::setLength ( unsigned short  value)

sets the packet length (byte 5 and 6)

Parameters
valuethe new packet length
void whisper_library::UdpPacket::setPacket ( std::vector< bool >  packet)

sets the whole packet

Parameters
packetthe new packet as bits
void whisper_library::UdpPacket::setSourcePort ( unsigned short  value)

sets the source port (byte 1 and 2)

Parameters
valuethe new source port
unsigned short whisper_library::UdpPacket::sourcePort ( ) const
Returns
the source port (byte 1 and 2)
string whisper_library::UdpPacket::toString ( )

Creates a string that contains all header fields.

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  ostream,
const UdpPacket packet 
)
friend

streamoperator to write the whole packet to a std::ostream