Class: FFI::PCap::Packets::TCP

Inherits:
Struct
  • Object
show all
Includes:
Packet
Defined in:
lib/pcap/packets/tcp.rb

Constant Summary collapse

FLAGS =

TCP flags

[
  # Null flags
  NULL = 0x00,

  # Final packet flag
  FIN = 0x01,

  # Synchronization packet flag
  SYN = 0x02,

  # Reset packet flag
  RST = 0x04,

  # Push packet flag
  PUSH = 0x08,

  # Acknowledgement packet flag
  ACK = 0x10,

  # Urgent data packet flag
  URG = 0x20,

  # ECE packet flag
  ECE = 0x40,

  # CWR packet flag
  CWR = 0x80,

  # All combined flags
  XMAS = (FIN | SYN | RST | PUSH | ACK | URG | ECE | CWR)
]

Instance Method Summary collapse

Instance Method Details

#ackObject

Returns the acknowledgement number of the packet.



80
81
82
# File 'lib/pcap/packets/tcp.rb', line 80

def ack
  self[:th_ack]
end

#ack?Boolean

Returns true if the packet has the ACK flag set, returns false otherwise.

Returns:

  • (Boolean)


134
135
136
# File 'lib/pcap/packets/tcp.rb', line 134

def ack?
  (self[:th_flags] & ACK) != 0
end

#cwr?Boolean

Returns true if the packet has the CWR flag set, returns false otherwise.

Returns:

  • (Boolean)


158
159
160
# File 'lib/pcap/packets/tcp.rb', line 158

def cwr?
  (self[:th_flags] & CWR) != 0
end

#dest_portObject

Returns the destination port.



66
67
68
# File 'lib/pcap/packets/tcp.rb', line 66

def dest_port
  self[:th_dport]
end

#ece?Boolean

Returns true if the packet has the ECE flag set, returns false otherwise.

Returns:

  • (Boolean)


150
151
152
# File 'lib/pcap/packets/tcp.rb', line 150

def ece?
  (self[:th_flags] & ECE) != 0
end

#fin?Boolean

Returns true if the packet has the FIN flag set, returns false otherwise.

Returns:

  • (Boolean)


102
103
104
# File 'lib/pcap/packets/tcp.rb', line 102

def fin?
  (self[:th_flags] & FIN) != 0
end

#null?Boolean

Returns true if the packet has no flags set, false otherwise.

Returns:

  • (Boolean)


94
95
96
# File 'lib/pcap/packets/tcp.rb', line 94

def null?
  self[:th_flags] == NULL
end

#offsetObject

Returns the data offset for the packet.



87
88
89
# File 'lib/pcap/packets/tcp.rb', line 87

def offset
  (self[:th_offx2] & 0xf0) >> 4
end

#push?Boolean

Returns true if the packet has the PUSH flag set, returns false otherwise.

Returns:

  • (Boolean)


126
127
128
# File 'lib/pcap/packets/tcp.rb', line 126

def push?
  (self[:th_flags] & PUSH) != 0
end

#rst?Boolean

Returns true if the packet has the RST flag set, returns false otherwise.

Returns:

  • (Boolean)


118
119
120
# File 'lib/pcap/packets/tcp.rb', line 118

def rst?
  (self[:th_flags] & RST) != 0
end

#seqObject

Returns the sequence number of the packet.



73
74
75
# File 'lib/pcap/packets/tcp.rb', line 73

def seq
  self[:th_seq]
end

#src_portObject

Returns the source port.



59
60
61
# File 'lib/pcap/packets/tcp.rb', line 59

def src_port
  self[:th_sport]
end

#syn?Boolean

Returns true if the packet has the SYN flag set, returns false otherwise.

Returns:

  • (Boolean)


110
111
112
# File 'lib/pcap/packets/tcp.rb', line 110

def syn?
  (self[:th_flags] & SYN) != 0
end

#urg?Boolean

Returns true if the packet has the URG flag set, returns false otherwise.

Returns:

  • (Boolean)


142
143
144
# File 'lib/pcap/packets/tcp.rb', line 142

def urg?
  (self[:th_flags] & URG) != 0
end

#xmas?Boolean

Returns true if the packet has all flags set, false otherwise.

Returns:

  • (Boolean)


165
166
167
# File 'lib/pcap/packets/tcp.rb', line 165

def xmas?
  (self[:th_flags] & XMAS) == XMAS
end