lib/packetgen/header/tcp.rb in packetgen-2.6.0 vs lib/packetgen/header/tcp.rb in packetgen-2.7.0
- old
+ new
@@ -5,11 +5,10 @@
# frozen_string_literal: true
module PacketGen
module Header
-
# A TCP header consists of:
# * a source port ({#sport}, {Types::Int16} type),
# * a destination port ({#dport}, +Int16+ type),
# * a sequence number ({#seqnum}, {Types::Int32} type),
# * an acknownledge number ({#acknum}, +Int32+ type),
@@ -145,12 +144,12 @@
# @!attribute reserved
# @return [Integer] 3-bit reserved from {#u16}
# @!attribute flags
# @return [Integer] 9-bit flags from {#u16}
define_bit_fields_on :u16, :data_offset, 4, :reserved, 3, :flags, 9
- alias :hlen :data_offset
- alias :hlen= :data_offset=
+ alias hlen data_offset
+ alias hlen= data_offset=
# @!attribute flag_ns
# @return [Boolean] 1-bit NS flag
# @!attribute flag_cwr
# @return [Boolean] 1-bit CWR flag
@@ -203,13 +202,10 @@
# @return [Integer]
def calc_length
self[:data_offset] = 5 + self[:options].sz / 4
end
- alias hlen data_offset
- alias hlen= data_offset=
-
# @return [String]
def inspect
str = Inspect.dashed_line(self.class, 2)
shift = Inspect.shift_level(2)
fields.each do |attr|
@@ -218,21 +214,29 @@
if attr == :u16
doff = Inspect.int_dec_hex(data_offset, 1)
str << shift + Inspect::FMT_ATTR % ['', 'data_offset', doff]
str << shift + Inspect::FMT_ATTR % ['', 'reserved', reserved]
flags = ''.dup
- %w(ns cwr ece urg ack psh rst syn fin).each do |fl|
+ %w[ns cwr ece urg ack psh rst syn fin].each do |fl|
flags << (send("flag_#{fl}?") ? fl[0].upcase : '.')
end
str << shift + Inspect::FMT_ATTR % ['', 'flags', flags]
end
end
str
end
+
+ # Invert source and destination port numbers
+ # @return [self]
+ # @since 2.7.0
+ def reply!
+ self[:sport], self[:dport] = self[:dport], self[:sport]
+ self
+ end
end
self.add_class TCP
- IP.bind_header TCP, protocol: TCP::IP_PROTOCOL
- IPv6.bind_header TCP, next: TCP::IP_PROTOCOL
+ IP.bind TCP, protocol: TCP::IP_PROTOCOL
+ IPv6.bind TCP, next: TCP::IP_PROTOCOL
end
end