Whisper Library
|
Represents a tcp packet. More...
Public Member Functions | |
TcpPacket () | |
The empty constructor creates an empty tcp packet. | |
TcpPacket (vector< bool > content) | |
Create a packet based of a given boolean vector. More... | |
TcpPacket (uint inSourcePort, uint inDestPort, ulong inSequenceNumber, ulong inAckNumber, bitset< 4 > inDataOffset, uint inWindowSize, vector< bool > inOptions) | |
This constructor is used to fill in some of the important fields beforehand. More... | |
uint | sourcePort () const |
uint | destPort () const |
ulong | sequenceNumber () const |
ulong | acknowledgeNumber () const |
bitset< 4 > | dataOffset () const |
bitset< 3 > | reserved () const |
bitset< 9 > | flags () const |
bool | nonceSumFlag () const |
bool | congestionWindowReducedFlag () const |
bool | ecnEchoFlag () const |
bool | urgentFlag () const |
bool | acknowledgementFlag () const |
bool | pushFlag () const |
bool | resetFlag () const |
bool | synchronisationFlag () const |
bool | finishFlag () const |
uint | windowSize () const |
uint | checksum () const |
uint | urgentPointer () const |
vector< bool > | options () const |
vector< bool > | packet () const |
vector< bool > | data () const |
void | setSourcePort (uint val) |
void | setDestPort (uint val) |
void | setSequenceNumber (ulong val) |
void | setAcknowledgeNumber (ulong val) |
void | setDataOffset (bitset< 4 > val) |
void | setReserved (bitset< 3 > val) |
void | setFlags (bitset< 9 > val) |
void | setNonceSumFlag (bool val) |
void | setCongestionWindowReducedFlag (bool val) |
void | setEcnEchoFlag (bool val) |
void | setUrgentFlag (bool val) |
void | setAcknowledgementFlag (bool val) |
void | setPushFlag (bool val) |
void | setResetFlag (bool val) |
void | setSynchronisationFlag (bool val) |
void | setFinishFlag (bool val) |
void | setWindowSize (uint val) |
void | setChecksum (uint val) |
void | setUrgentPointer (uint val) |
void | setOptions (vector< bool > val) |
void | setData (vector< bool > val) |
void | setData (string data) |
void | setPacket (vector< bool > val) |
void | calculateChecksum (ulong sourceIp, ulong destIp, uint reservedBits, uint protocol) |
This function is used to calculate the tcp checksum. More... | |
![]() | |
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 | |
ulong | vectorToULong (uint start, uint end, const vector< bool > &vec) const |
This function is used to convert a vector into an unsigned integer value. More... | |
template<class T > | |
void | uIntToVector (uint start, uint end, vector< bool > &vec, T val) |
This function is used to insert an unsigned integer value into a given boolean vector. More... | |
template<class T > | |
vector< bool > | intToBoolVector (T val, uint size) |
This function is used to convert a given integer value into a boolean vector. More... | |
vector< bool > | oneComplementAdd (vector< bool > vec1, vector< bool > vec2) |
This function uses the one complement addition to add two 16 bit boolean vectors. More... | |
vector< vector< bool > > | split32BitVector (vector< bool > vec) |
This function splits a 32 bit boolean vector into two 16 bit vectors. More... | |
vector< vector< bool > > | splitHeaderTo16Bit () |
This function splits the whole TCP packet into a vector of 16bit boolean vectors. More... | |
vector< bool > | trimBigEndianVector (vector< bool > vec, uint size) |
This function trims a big endian boolean vector to a fixed size. More... | |
Private Attributes | |
vector< bool > | m_header |
This vector stores the bits 0-159 of the TCP header. These are fields but the options. | |
vector< bool > | m_options |
This vector stores the options field of the TCP header. | |
vector< bool > | m_data |
This vector stores data carrying bits of the TCP packet. | |
Represents a tcp packet.
All the different fields of the TCP packet can be accessed using getter and setter methods. To make the TCP packet valid, you must invoke calculate checksum first, after setting all the fields. Keep in mind that all information that is passed in binary format uses big endian notation.
whisper_library::TcpPacket::TcpPacket | ( | vector< bool > | content | ) |
Create a packet based of a given boolean vector.
content | The content to fill the packet |
whisper_library::TcpPacket::TcpPacket | ( | uint | inSourcePort, |
uint | inDestPort, | ||
ulong | inSequenceNumber, | ||
ulong | inAckNumber, | ||
bitset< 4 > | inDataOffset, | ||
uint | inWindowSize, | ||
vector< bool > | inOptions | ||
) |
This constructor is used to fill in some of the important fields beforehand.
inSourcePort | The source port as integer. Max value 2^16. |
inDestPort | The destination port as integer. Max value 2^16. |
inSequenceNumber | The sequence number of the packet. Max value 2^32. |
inAckNumber | The acknowledgement number of the packet. Max value 2^32. |
inDataOffset | The length of the options field in bytes. Max value 2^4. |
inWindowSize | The size of the packet in bytes. Max value 2^16. |
inOptions | The options as a vector of boolean values. Max size . |
bool whisper_library::TcpPacket::acknowledgementFlag | ( | ) | const |
ulong whisper_library::TcpPacket::acknowledgeNumber | ( | ) | const |
void whisper_library::TcpPacket::calculateChecksum | ( | ulong | sourceIp, |
ulong | destIp, | ||
uint | reservedBits, | ||
uint | protocol | ||
) |
This function is used to calculate the tcp checksum.
To do this it needs some additional information of the IP header as parameters.
sourceIp | IP adress of the sender as integer |
destIp | IP adress of the reciever as integer |
reservedBits | the value of the reserved bits of the IP header as integer |
protocol | the protocol used to send the data as integer value |
uint whisper_library::TcpPacket::checksum | ( | ) | const |
bool whisper_library::TcpPacket::congestionWindowReducedFlag | ( | ) | const |
vector< bool > whisper_library::TcpPacket::data | ( | ) | const |
bitset< 4 > whisper_library::TcpPacket::dataOffset | ( | ) | const |
uint whisper_library::TcpPacket::destPort | ( | ) | const |
bool whisper_library::TcpPacket::ecnEchoFlag | ( | ) | const |
bool whisper_library::TcpPacket::finishFlag | ( | ) | const |
bitset< 9 > whisper_library::TcpPacket::flags | ( | ) | const |
|
private |
This function is used to convert a given integer value into a boolean vector.
val | The value to be converted |
size | length of returned vector |
bool whisper_library::TcpPacket::nonceSumFlag | ( | ) | const |
|
private |
This function uses the one complement addition to add two 16 bit boolean vectors.
vec1 | The first 16bit boolean vector to be added. |
vec2 | The second 16bit boolean vector to be added. |
vector< bool > whisper_library::TcpPacket::options | ( | ) | const |
vector< bool > whisper_library::TcpPacket::packet | ( | ) | const |
bool whisper_library::TcpPacket::pushFlag | ( | ) | const |
bitset< 3 > whisper_library::TcpPacket::reserved | ( | ) | const |
bool whisper_library::TcpPacket::resetFlag | ( | ) | const |
ulong whisper_library::TcpPacket::sequenceNumber | ( | ) | const |
void whisper_library::TcpPacket::setAcknowledgementFlag | ( | bool | val | ) |
val | Indicates, that the acknowledgement field is significant. All packets after the initial SYN packet sent by the client should have this flag set. |
void whisper_library::TcpPacket::setAcknowledgeNumber | ( | ulong | val | ) |
val | The acknowledgement number of the packet. If the acknowledgement number is set, this is the next packet the reciever is expecting. All packets prior the acknowledgement number have been received. The first ACK sent by each end acknowledges the initial sequence number, but no data. |
void whisper_library::TcpPacket::setChecksum | ( | uint | val | ) |
val | The 16-bit checksum field is used for error checking of the header and data. |
void whisper_library::TcpPacket::setCongestionWindowReducedFlag | ( | bool | val | ) |
val | This flag is set by the sending host, to indicate that it received a TCP segment with the ECE flag set and that it responded using a congestion control mechanism. (RFC 3168) |
void whisper_library::TcpPacket::setData | ( | vector< bool > | val | ) |
val | Set the data of the packet. |
void whisper_library::TcpPacket::setData | ( | string | data | ) |
data | Set the data of the packet. |
void whisper_library::TcpPacket::setDataOffset | ( | bitset< 4 > | val | ) |
val | The size of the tcp header in 32-bit words. The smallest size without options is 5. The maximum size is 15. |
void whisper_library::TcpPacket::setDestPort | ( | uint | val | ) |
val | The port at which the packet is received. Max value is 2^16. |
void whisper_library::TcpPacket::setEcnEchoFlag | ( | bool | val | ) |
val | - If the SYN flag is set, the TCP peer is ECN capable.
|
void whisper_library::TcpPacket::setFinishFlag | ( | bool | val | ) |
val | No more data from sender. |
void whisper_library::TcpPacket::setFlags | ( | bitset< 9 > | val | ) |
val | Set all the flags of the tcp header with one bitset. Their order is: NS, CWR, ECN, URG, ACK, PSH, SYN, FIN. For more detailed information see the corresponding setters. |
void whisper_library::TcpPacket::setNonceSumFlag | ( | bool | val | ) |
val | ECN-nounce concealment protection. (RFC 3540) |
void whisper_library::TcpPacket::setOptions | ( | vector< bool > | val | ) |
val | A set of options. The size has to be dividable by 32. |
void whisper_library::TcpPacket::setPacket | ( | vector< bool > | val | ) |
val | Convert a boolean vector into the packet object. |
void whisper_library::TcpPacket::setPushFlag | ( | bool | val | ) |
val | Asks to push the buffered data to the recieving application. |
void whisper_library::TcpPacket::setReserved | ( | bitset< 3 > | val | ) |
val | The reserved bits of the tcp header. Keep in mind that this is, like all information in the header, in big endian notation. |
void whisper_library::TcpPacket::setResetFlag | ( | bool | val | ) |
val | Reset the connection. |
void whisper_library::TcpPacket::setSequenceNumber | ( | ulong | val | ) |
val | The sequence number of the packet.
|
void whisper_library::TcpPacket::setSourcePort | ( | uint | val | ) |
val | The port that is used to send the packet. Max value is 2^16. |
void whisper_library::TcpPacket::setSynchronisationFlag | ( | bool | val | ) |
val | Synchronize sequence numbers. Only the first packet sent from each end should have this flag set. Some other flags change the meaning based on this flag and some are only valid for when it is set and others when it´s clear. |
void whisper_library::TcpPacket::setUrgentFlag | ( | bool | val | ) |
val | Indicates, that the urgent pointer field is significant. |
void whisper_library::TcpPacket::setUrgentPointer | ( | uint | val | ) |
val | If the URG flag is set, then this 16-bit field is an offset from the sequence number indicating the last urgent data byte. |
void whisper_library::TcpPacket::setWindowSize | ( | uint | val | ) |
val | The size of the recieve window, which specifies the number of window size units (by default, bytes) (beyond the sequence number in the acknowledgement field) that the sender of this segment is currently willing to recieve. |
uint whisper_library::TcpPacket::sourcePort | ( | ) | const |
|
private |
This function splits a 32 bit boolean vector into two 16 bit vectors.
vec | The vector to be split up. |
|
private |
This function splits the whole TCP packet into a vector of 16bit boolean vectors.
bool whisper_library::TcpPacket::synchronisationFlag | ( | ) | const |
|
private |
This function trims a big endian boolean vector to a fixed size.
vec | The vector to be trimmed. |
size | The new size of the vector. |
|
private |
This function is used to insert an unsigned integer value into a given boolean vector.
start | The index where the first bit will be inserted |
end | The index where the last bit will be inserted |
vec | The vector the value will be inserted in |
val | The value to be inserted |
bool whisper_library::TcpPacket::urgentFlag | ( | ) | const |
uint whisper_library::TcpPacket::urgentPointer | ( | ) | const |
|
private |
This function is used to convert a vector into an unsigned integer value.
start | the starting bit of the value in the given vector |
end | the last bit of the value in the given vector |
vec | the vector the value is stored in |
uint whisper_library::TcpPacket::windowSize | ( | ) | const |