1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-27 12:14:26 +01:00

Added a const overload of TCP::get_flag. Added TCP::flags.

This commit is contained in:
Matias Fontanini
2013-06-17 21:25:30 -03:00
parent acff8f1e1f
commit f385e4e975
4 changed files with 97 additions and 15 deletions

View File

@@ -241,9 +241,9 @@ namespace Tins {
* Creates an ARP Request PDU and embeds it within a Layer 2 PDU ready to be
* sent.
*
* \param target IPv4Address with the target's IP.
* \param sender IPv4Address with the sender's IP.
* \param hw_snd uint8_t array of 6 bytes containing the sender's hardware address.
* \param target The target's IP address.
* \param sender The sender's IP address.
* \param hw_snd The sender's hardware address.
* \return Returns a EthernetII containing the ARP Request.
*/
static EthernetII make_arp_request(ipaddress_type target,
@@ -255,10 +255,10 @@ namespace Tins {
* Creates an ARP Reply PDU and embeds it within a Layer 2 PDU ready to be
* sent.
*
* \param target IPv4Address with the target's IP.
* \param sender IPv4Address with the sender's IP.
* \param hw_tgt uint8_t array of 6 bytes containing the target's hardware address.
* \param hw_snd uint8_t array of 6 bytes containing the sender's hardware address.
* \param target The target's IP address.
* \param sender The sender's IP address.
* \param hw_tgt The target's hardware address.
* \param hw_snd The sender's hardware address.
* \return Returns an EthetnetII containing the ARP Replay.
*/
static EthernetII make_arp_reply(ipaddress_type target,

View File

@@ -64,14 +64,14 @@ namespace Tins {
* These flags identify those supported by the TCP PDU.
*/
enum Flags {
FIN,
SYN,
RST,
PSH,
ACK,
URG,
ECE,
CWR
FIN = 1,
SYN = 2,
RST = 4,
PSH = 8,
ACK = 16,
URG = 32,
ECE = 64,
CWR = 128
};
/**
@@ -208,6 +208,32 @@ namespace Tins {
* \return The value of the flag.
*/
small_uint<1> get_flag(Flags tcp_flag);
/**
* \brief Gets the value of a flag.
*
* \param tcp_flag The polled flag.
* \return The value of the flag.
*/
small_uint<1> get_flag(Flags tcp_flag) const;
/**
*
* \brief Gets the flags' values.
*
* All of the set flags will be joined together into
* a 12 bit value. This way, you can check for multiple
* flags at the same time:
*
* \code
* TCP tcp = ...;
* if(tcp.flags() == (TCP::SYN | TCP::ACK))
* // It's a SYN+ACK!
* \endcode
*
* \return The value of the flags field.
*/
small_uint<12> flags() const;
/* Setters */
@@ -353,6 +379,25 @@ namespace Tins {
*/
void set_flag(Flags tcp_flag, small_uint<1> value);
/**
* \brief Sets the value of the flag fields.
*
* This method can be used to set several flags at the
* same time.
*
* \code
* TCP tcp = ...;
* tcp.flags(TCP::SYN | TCP::ACK);
* // ...
* // only set the ACK, keeping the rest of the old flags.
* tcp.flags(tcp.flags() | TCP::ACK);
* \endcode
*
* \param value The new value of the flags.
*/
void flags(small_uint<12> value);
/**
* \brief Adds a TCP option.
*