Class: Procfs2::ProcNetUdpSocket

Inherits:
Object
  • Object
show all
Defined in:
lib/procfs2/proc_net_udp_socket.rb

Constant Summary collapse

HEADERS =
%i[
  id
  local_address_port
  remote_address_port
  state
  transmit_receive_queue
  timer_and_jiffies
  retransmit
  uid
  timeout
  inode
  socket_reference_count
  socket_location
  drops
].freeze
STATE_STR =
{
  0 => 'UNKNOWN',
  1 => 'ESTABLISHED',
  2 => 'SYN_SENT',
  3 => 'SYN_RECV',
  4 => 'FIN_WAIT1',
  5 => 'FIN_WAIT2',
  6 => 'TIME_WAIT',
  7 => 'CLOSE',
  8 => 'CLOSE_WAIT',
  9 => 'LAST_ACK',
  10 => 'LISTEN',
  11 => 'CLOSING',
  12 => 'NEW_SYN_RECV',
  13 => 'MAX_STATE'
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, local_address:, local_port:, remote_address:, remote_port:, state:, transmit_queue:, receive_queue:, uid:, inode:, drops:, **extra) ⇒ ProcNetUdpSocket

Returns a new instance of ProcNetUdpSocket.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/procfs2/proc_net_udp_socket.rb', line 41

def initialize(id:, local_address:, local_port:, remote_address:, remote_port:, state:,
               transmit_queue:, receive_queue:, uid:, inode:, drops:, **extra)
  @id = id
  @local_address = local_address
  @local_port = local_port
  @remote_address = remote_address
  @remote_port = remote_port
  @state = state
  @transmit_queue = transmit_queue
  @receive_queue = receive_queue
  @uid = uid
  @inode = inode
  @drops = drops

  @extra = extra
end

Instance Attribute Details

#dropsObject (readonly)

Returns the value of attribute drops.



38
39
40
# File 'lib/procfs2/proc_net_udp_socket.rb', line 38

def drops
  @drops
end

#idObject (readonly)

Returns the value of attribute id.



38
39
40
# File 'lib/procfs2/proc_net_udp_socket.rb', line 38

def id
  @id
end

#inodeObject (readonly)

Returns the value of attribute inode.



38
39
40
# File 'lib/procfs2/proc_net_udp_socket.rb', line 38

def inode
  @inode
end

#local_addressObject (readonly)

Returns the value of attribute local_address.



38
39
40
# File 'lib/procfs2/proc_net_udp_socket.rb', line 38

def local_address
  @local_address
end

#local_portObject (readonly)

Returns the value of attribute local_port.



38
39
40
# File 'lib/procfs2/proc_net_udp_socket.rb', line 38

def local_port
  @local_port
end

#receive_queueObject (readonly)

Returns the value of attribute receive_queue.



38
39
40
# File 'lib/procfs2/proc_net_udp_socket.rb', line 38

def receive_queue
  @receive_queue
end

#remote_addressObject (readonly)

Returns the value of attribute remote_address.



38
39
40
# File 'lib/procfs2/proc_net_udp_socket.rb', line 38

def remote_address
  @remote_address
end

#remote_portObject (readonly)

Returns the value of attribute remote_port.



38
39
40
# File 'lib/procfs2/proc_net_udp_socket.rb', line 38

def remote_port
  @remote_port
end

#stateObject (readonly)

Returns the value of attribute state.



38
39
40
# File 'lib/procfs2/proc_net_udp_socket.rb', line 38

def state
  @state
end

#transmit_queueObject (readonly)

Returns the value of attribute transmit_queue.



38
39
40
# File 'lib/procfs2/proc_net_udp_socket.rb', line 38

def transmit_queue
  @transmit_queue
end

#uidObject (readonly)

Returns the value of attribute uid.



38
39
40
# File 'lib/procfs2/proc_net_udp_socket.rb', line 38

def uid
  @uid
end

Class Method Details

.build_from_line(line) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/procfs2/proc_net_udp_socket.rb', line 67

def build_from_line(line)
  info = HEADERS.zip(line.strip.split).to_h
  options = {}

  options[:id] = info[:id].chomp(':').to_i
  options[:local_address], options[:local_port] = parse_address_hex(info[:local_address_port])
  options[:remote_address], options[:remote_port] = parse_address_hex(info[:remote_address_port])
  options[:state] = info[:state].hex
  options[:transmit_queue], options[:receive_queue] = info[:transmit_receive_queue].split(':').map(&:hex)
  options[:timer_active], options[:jiffries] = info[:timer_and_jiffies].split(':').map(&:hex)
  options[:retransmit] = info[:retransmit].hex
  options[:uid] = info[:uid].to_i
  options[:timeout] = info[:timeout].to_i
  options[:inode] = info[:inode].to_i
  options[:socket_reference_count] = info[:socket_reference_count].to_i
  options[:socket_location] = info[:socket_location]
  options[:drops] = info[:drops].to_i

  new(**options)
end

.parse_address_hex(address_port_hex) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'lib/procfs2/proc_net_udp_socket.rb', line 88

def parse_address_hex(address_port_hex)
  address_hex, port_hex = address_port_hex.split(':')
  address = [address_hex[6..7],
             address_hex[4..5],
             address_hex[2..3],
             address_hex[0..1]].map(&:hex).join('.')
  port = port_hex.hex
  [address, port]
end

Instance Method Details

#state_strObject



62
63
64
# File 'lib/procfs2/proc_net_udp_socket.rb', line 62

def state_str
  STATE_STR[state]
end

#typeObject



58
59
60
# File 'lib/procfs2/proc_net_udp_socket.rb', line 58

def type
  'udp'
end