Class: Ifconfig_interface

Inherits:
Object
  • Object
show all
Defined in:
lib/Unix/ifconfig_interface.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string = '') ⇒ Ifconfig_interface

Returns a new instance of Ifconfig_interface.



14
15
16
17
# File 'lib/Unix/ifconfig_interface.rb', line 14

def initialize(string = '')
  @interface_raw = []
  parse(string) unless string.empty?
end

Instance Attribute Details

#broadcastObject (readonly)

Returns the value of attribute broadcast.



9
10
11
# File 'lib/Unix/ifconfig_interface.rb', line 9

def broadcast
  @broadcast
end

#flags_rawObject (readonly)

Returns the value of attribute flags_raw.



5
6
7
# File 'lib/Unix/ifconfig_interface.rb', line 5

def flags_raw
  @flags_raw
end

#inetObject (readonly)

Returns the value of attribute inet.



6
7
8
# File 'lib/Unix/ifconfig_interface.rb', line 6

def inet
  @inet
end

#inet6Object (readonly)

Returns the value of attribute inet6.



7
8
9
# File 'lib/Unix/ifconfig_interface.rb', line 7

def inet6
  @inet6
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/Unix/ifconfig_interface.rb', line 4

def name
  @name
end

#netmaskObject (readonly)

Returns the value of attribute netmask.



8
9
10
# File 'lib/Unix/ifconfig_interface.rb', line 8

def netmask
  @netmask
end

#rfc1323Object (readonly)

Returns the value of attribute rfc1323.



12
13
14
# File 'lib/Unix/ifconfig_interface.rb', line 12

def rfc1323
  @rfc1323
end

#string_rawObject (readonly)

Returns the value of attribute string_raw.



3
4
5
# File 'lib/Unix/ifconfig_interface.rb', line 3

def string_raw
  @string_raw
end

#tcp_recvspaceObject (readonly)

Returns the value of attribute tcp_recvspace.



11
12
13
# File 'lib/Unix/ifconfig_interface.rb', line 11

def tcp_recvspace
  @tcp_recvspace
end

#tcp_sendspaceObject (readonly)

Returns the value of attribute tcp_sendspace.



10
11
12
# File 'lib/Unix/ifconfig_interface.rb', line 10

def tcp_sendspace
  @tcp_sendspace
end

Instance Method Details

#parse(string) ⇒ 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
# File 'lib/Unix/ifconfig_interface.rb', line 19

def parse(string)
  @string_raw = string

  regexp_ipv4 = %r{^(\w+\d+):\s+flags=([\w\,]+)\s*
\s+inet\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+netmask\s+(0x\w+)\s+broadcast\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s*
\s+tcp_sendspace\s+(\d+)\s+tcp_recvspace\s+(\d+)\s+rfc1323\s+(\d)\s*$
}mx

  regexp_ipv6 = %r{^(\w+\d+):\s+flags=([\w\,]+)\s*
\s+inet\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+netmask\s+(0x\w+)\s+broadcast\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s*
\s+inet6\s+([\:\%\/\d]+)\s*
\s+tcp_sendspace\s+(\d+)\s+tcp_recvspace\s+(\d+)\s+rfc1323\s+(\d)\s*$
}mx

  if match = regexp_ipv4.match(string)
    @name = match[1]
    @flags_raw = match[2]
    @inet = match[3]
    @netmask = match[4]
    @broadcast = match[5]
    @tcp_sendspace = match[6].to_i
    @tcp_recvspace = match[7].to_i
    @rfc1323 = match[8].to_i
  elsif match = regexp_ipv6.match(string)
    @name = match[1]
    @flags_raw = match[2]
    @inet = match[3]
    @netmask = match[4]
    @broadcast = match[5]
    @inet6 = match[6]
    @tcp_sendspace = match[7].to_i
    @tcp_recvspace = match[8].to_i
    @rfc1323 = match[9].to_i
  else
    raise "Class:Unix:ifconfig_interface, function: parse, RegExp couldn't decode string >>#{string}<<"
  end
end