procfs2 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f375fcd2d93a0c3a12c604830459e97eda2d4c744b8e07287755dd034e32630
4
- data.tar.gz: cad7c93a47748b62840015a1bceb80d9c731d32999f8c5ad322558173d4b5599
3
+ metadata.gz: bc90062ccc4e6d1ca9be21ab4032a00305d341fbe53fd1fd2e059f067e9e5a16
4
+ data.tar.gz: fa40ce57134a641a5ff737501019a66719a3a42af7980c0b58889aa9fd6033fb
5
5
  SHA512:
6
- metadata.gz: 7dfdfe59866bf4783b82c0a22b8fdd9faae9bccec54fb118a59ef216775f2b7f8d4df4dbd0edbe2eea4b8eec57f791363e93ad8cb703c4f02a596552771a3dce
7
- data.tar.gz: 25797138a244a267e4d8cf36959c4429c7a4d3d24369bfefefe97a8403fab419cbcc0d53950b44e710971b80ef323a1dd261463901f395601e841aee67886f86
6
+ metadata.gz: e930a00862eff654f9a09ed669ca78c671cf320d44f905acf1c70aa4af43579269104c64eb8d508fc9b8d79a57a45df486ad3d46897e24c5d0f238fb110bafe8
7
+ data.tar.gz: b727eeeb2fbb9e0b616587afe81302550863aef2f1f21428780aa3f6a55b566d6562a4b4bf2c28a2fe3d77ef6108e8a2210bfd52d19e7bd5aa8d867d62f018ba
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Procfs2
4
4
  class ProcItem
5
- attr_reader :_parent, :_raw_content, :_data
5
+ attr_reader :_parent, :_data
6
6
 
7
7
  def initialize(parent:)
8
8
  @_parent = parent
@@ -40,11 +40,19 @@ module Procfs2
40
40
 
41
41
  def _parse_content; end
42
42
 
43
- def method_missing(method_name, *args, **kwargs)
44
- return unless _data
43
+ def method_missing(method, *args, **kwargs)
44
+ if _data.respond_to?(:key?)
45
+ return _data[method.to_sym] if _data.key?(method.to_sym)
46
+ return _data[method.to_s] if _data.key?(method.to_s)
47
+ end
45
48
 
46
- return _data[method_name.to_sym] if _data.key?(method_name.to_sym)
47
- return _data[method_name.to_s] if _data.key?(method_name.to_s)
49
+ super
50
+ end
51
+
52
+ def respond_to_missing?(method, *)
53
+ if _data.respond_to?(:key?) && (_data.key?(method.to_sym) || _data.key?(method.to_s))
54
+ return True
55
+ end
48
56
 
49
57
  super
50
58
  end
@@ -2,11 +2,13 @@
2
2
 
3
3
  require_relative 'proc_module'
4
4
  require_relative 'proc_net_tcp'
5
+ require_relative 'proc_net_udp'
5
6
 
6
7
  module Procfs2
7
8
  class ProcNet < ProcModule
8
9
  LABEL = :net
9
10
 
10
11
  provide ProcNetTcp
12
+ provide ProcNetUdp
11
13
  end
12
14
  end
@@ -9,9 +9,9 @@ module Procfs2
9
9
  state
10
10
  transmit_receive_queue
11
11
  timer_and_jiffies
12
- unrecovered_rto_timeouts
12
+ retransmit
13
13
  uid
14
- unanswered_0_window_probes
14
+ timeout
15
15
  inode
16
16
  socket_reference_count
17
17
  socket_location
@@ -77,9 +77,9 @@ module Procfs2
77
77
  options[:state] = info[:state].hex
78
78
  options[:transmit_queue], options[:receive_queue] = info[:transmit_receive_queue].split(':').map(&:hex)
79
79
  options[:timer_active], options[:jiffries] = info[:timer_and_jiffies].split(':').map(&:hex)
80
- options[:unrecovered_rto_timeouts] = info[:unrecovered_rto_timeouts].hex
80
+ options[:retransmit] = info[:retransmit].hex
81
81
  options[:uid] = info[:uid].to_i
82
- options[:unanswered_0_window_probes] = info[:unanswered_0_window_probes].hex
82
+ options[:timeout] = info[:timeout].to_i
83
83
  options[:inode] = info[:inode].to_i
84
84
  options[:socket_reference_count] = info[:socket_reference_count].to_i
85
85
  options[:socket_location] = info[:socket_location]
@@ -95,9 +95,9 @@ module Procfs2
95
95
  def parse_address_hex(address_port_hex)
96
96
  address_hex, port_hex = address_port_hex.split(':')
97
97
  address = [address_hex[6..7],
98
- address_hex[5..4],
99
- address_hex[3..2],
100
- address_hex[1..0]].map(&:hex).join('.')
98
+ address_hex[4..5],
99
+ address_hex[2..3],
100
+ address_hex[0..1]].map(&:hex).join('.')
101
101
  port = port_hex.hex
102
102
  [address, port]
103
103
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'proc_item'
4
+ require_relative 'proc_net_udp_socket'
5
+
6
+ module Procfs2
7
+ class ProcNetUdp < ProcItem
8
+ LABEL = :udp
9
+
10
+ def _load_content
11
+ @_data = []
12
+
13
+ lines = _raw_content.lines
14
+ lines.shift
15
+
16
+ @_data = lines.map { |socket_line| ProcNetUdpSocket.build_from_line(socket_line) }
17
+ end
18
+
19
+ def by_id(id)
20
+ @_data.find { |socket| socket.id == id.to_i }
21
+ end
22
+
23
+ def by_inode(inode)
24
+ @_data.find { |socket| socket.inode == inode.to_i }
25
+ end
26
+
27
+ def each(&block)
28
+ _data&.each(&block)
29
+ end
30
+
31
+ include Enumerable
32
+ end
33
+ end
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Procfs2
4
+ class ProcNetUdpSocket
5
+ HEADERS = %i[
6
+ id
7
+ local_address_port
8
+ remote_address_port
9
+ state
10
+ transmit_receive_queue
11
+ timer_and_jiffies
12
+ retransmit
13
+ uid
14
+ timeout
15
+ inode
16
+ socket_reference_count
17
+ socket_location
18
+ drops
19
+ ].freeze
20
+
21
+ STATE_STR = {
22
+ 0 => 'UNKNOWN',
23
+ 1 => 'ESTABLISHED',
24
+ 2 => 'SYN_SENT',
25
+ 3 => 'SYN_RECV',
26
+ 4 => 'FIN_WAIT1',
27
+ 5 => 'FIN_WAIT2',
28
+ 6 => 'TIME_WAIT',
29
+ 7 => 'CLOSE',
30
+ 8 => 'CLOSE_WAIT',
31
+ 9 => 'LAST_ACK',
32
+ 10 => 'LISTEN',
33
+ 11 => 'CLOSING',
34
+ 12 => 'NEW_SYN_RECV',
35
+ 13 => 'MAX_STATE'
36
+ }.freeze
37
+
38
+ attr_reader :id, :local_address, :local_port, :remote_address, :remote_port, :state,
39
+ :transmit_queue, :receive_queue, :uid, :inode, :drops
40
+
41
+ def initialize(id:, local_address:, local_port:, remote_address:, remote_port:, state:,
42
+ transmit_queue:, receive_queue:, uid:, inode:, drops:, **extra)
43
+ @id = id
44
+ @local_address = local_address
45
+ @local_port = local_port
46
+ @remote_address = remote_address
47
+ @remote_port = remote_port
48
+ @state = state
49
+ @transmit_queue = transmit_queue
50
+ @receive_queue = receive_queue
51
+ @uid = uid
52
+ @inode = inode
53
+ @drops = drops
54
+
55
+ @extra = extra
56
+ end
57
+
58
+ def type
59
+ 'udp'
60
+ end
61
+
62
+ def state_str
63
+ STATE_STR[state]
64
+ end
65
+
66
+ class << self
67
+ def build_from_line(line)
68
+ info = HEADERS.zip(line.strip.split).to_h
69
+ options = {}
70
+
71
+ options[:id] = info[:id].chomp(':').to_i
72
+ options[:local_address], options[:local_port] = parse_address_hex(info[:local_address_port])
73
+ options[:remote_address], options[:remote_port] = parse_address_hex(info[:remote_address_port])
74
+ options[:state] = info[:state].hex
75
+ options[:transmit_queue], options[:receive_queue] = info[:transmit_receive_queue].split(':').map(&:hex)
76
+ options[:timer_active], options[:jiffries] = info[:timer_and_jiffies].split(':').map(&:hex)
77
+ options[:retransmit] = info[:retransmit].hex
78
+ options[:uid] = info[:uid].to_i
79
+ options[:timeout] = info[:timeout].to_i
80
+ options[:inode] = info[:inode].to_i
81
+ options[:socket_reference_count] = info[:socket_reference_count].to_i
82
+ options[:socket_location] = info[:socket_location]
83
+ options[:drops] = info[:drops].to_i
84
+
85
+ new(**options)
86
+ end
87
+
88
+ def parse_address_hex(address_port_hex)
89
+ address_hex, port_hex = address_port_hex.split(':')
90
+ address = [address_hex[6..7],
91
+ address_hex[4..5],
92
+ address_hex[2..3],
93
+ address_hex[0..1]].map(&:hex).join('.')
94
+ port = port_hex.hex
95
+ [address, port]
96
+ end
97
+ end
98
+ end
99
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Procfs2
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: procfs2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Tych
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-10 00:00:00.000000000 Z
11
+ date: 2024-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bump
@@ -183,6 +183,8 @@ files:
183
183
  - lib/procfs2/proc_net.rb
184
184
  - lib/procfs2/proc_net_tcp.rb
185
185
  - lib/procfs2/proc_net_tcp_socket.rb
186
+ - lib/procfs2/proc_net_udp.rb
187
+ - lib/procfs2/proc_net_udp_socket.rb
186
188
  - lib/procfs2/proc_pid.rb
187
189
  - lib/procfs2/proc_version.rb
188
190
  - lib/procfs2/version.rb