Class: Mu::Pcap::SCTP::Parameter

Inherits:
Packet
  • Object
show all
Defined in:
lib/mu/pcap/sctp/parameter.rb,
lib/mu/pcap/sctp/parameter/ip_address.rb

Direct Known Subclasses

IpAddress

Defined Under Namespace

Classes: IpAddress

Constant Summary

Constants inherited from Packet

Packet::IGNORE_UDP_PORTS

Instance Attribute Summary collapse

Attributes inherited from Packet

#payload, #payload_raw

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Packet

#==, #deepdup, #flow_id, isolate_l7, normalize, #payload_bytes, #to_bytes

Constructor Details

#initializeParameter

Returns a new instance of Parameter.



12
13
14
15
16
17
# File 'lib/mu/pcap/sctp/parameter.rb', line 12

def initialize
    super
    
    @type  = 0
    @size  = 0
end

Instance Attribute Details

#sizeObject

Returns the value of attribute size.



10
11
12
# File 'lib/mu/pcap/sctp/parameter.rb', line 10

def size
  @size
end

#typeObject

Returns the value of attribute type.



10
11
12
# File 'lib/mu/pcap/sctp/parameter.rb', line 10

def type
  @type
end

Class Method Details

.dummy_parameter(type, size, bytes) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/mu/pcap/sctp/parameter.rb', line 91

def self.dummy_parameter type, size, bytes
    # Create new dummy parameter
    parameter       = Parameter.new
    parameter.type  = type
    parameter.size  = size
    
    # Save the payload
    parameter.payload = bytes[4..parameter.padded_size - 1]
    parameter.payload_raw = parameter.payload

    # Return the result
    return parameter
end

.from_bytes(bytes) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/mu/pcap/sctp/parameter.rb', line 19

def self.from_bytes bytes
    # Basic validation
    Pcap.assert(bytes.length >= 4,
                "Truncated parameter header: 4 > #{bytes.length}")
    
    # Read chunk header
    type, size = bytes.unpack('nn')
    
    # Validate chunk size
    Pcap.assert(bytes.length >= size,
                "Truncated parameter: #{size} set, #{bytes.length} available")
    
    # Create chunk based on type
    case type
        when PARAM_IPV4
            parameter = IpAddress.from_bytes(type, size, bytes[4..-1])
        when PARAM_IPV6
            parameter = IpAddress.from_bytes(type, size, bytes[4..-1])
        when PARAM_STATE_COOKIE
            parameter = dummy_parameter(type, size, bytes)
        when PARAM_COOKIE_PRESERVATIVE
            parameter = dummy_parameter(type, size, bytes)
        when PARAM_HOST_NAME_ADDR
            parameter = dummy_parameter(type, size, bytes)
        when PARAM_SUPPORTED_ADDR_TYPES
            parameter = dummy_parameter(type, size, bytes)
        when PARAM_ECN
            parameter = dummy_parameter(type, size, bytes)
        when PARAM_RANDOM
            parameter = dummy_parameter(type, size, bytes)
        when PARAM_CHUNK_LIST
            parameter = dummy_parameter(type, size, bytes)
        when PARAM_HMAC_ALGORITHM
            parameter = dummy_parameter(type, size, bytes)
        when PARAM_PADDING
            parameter = dummy_parameter(type, size, bytes)
        when PARAM_SUPPORTED_EXTENSIONS
            parameter = dummy_parameter(type, size, bytes)
        when PARAM_FORWARD_TSN
            parameter = dummy_parameter(type, size, bytes)
        when PARAM_SET_PRIMARY_ADDR
            parameter = dummy_parameter(type, size, bytes)
        when PARAM_ADAPTATION_LAYER_INDICATION
            parameter = dummy_parameter(type, size, bytes)
        else
            parameter = dummy_parameter(type, size, bytes)
    end
    
    # Return the result
    return parameter
end

Instance Method Details

#padded_sizeObject



79
80
81
82
83
84
85
# File 'lib/mu/pcap/sctp/parameter.rb', line 79

def padded_size
    if 0 == @size % 4
        return @size
    else
        return (@size + 4 - (@size % 4))
    end
end

#to_sObject



87
88
89
# File 'lib/mu/pcap/sctp/parameter.rb', line 87

def to_s
    return "parameter(%d, %d)" % [@type, @size]
end

#write(io, ip) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/mu/pcap/sctp/parameter.rb', line 71

def write io, ip
    header = [@type, @size].pack('nn')
    
    # Write Parameter header followed by the payload
    io.write(header)
    io.write(@payload_raw)
end