macaddr-steakknife 1.8.3 → 1.8.4

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
  SHA1:
3
- metadata.gz: 973f7962c2f381a12ff7a080e3ad9238105c1666
4
- data.tar.gz: 654b78b7c8e26698780ec9bb84566ee8adea38d9
3
+ metadata.gz: 890f0a3e388843c737f822965f48050fa402616e
4
+ data.tar.gz: 7c09951010eb863022305b80c45a063e0509137d
5
5
  SHA512:
6
- metadata.gz: ec699f79fe8d226417175b104d7e34a09141ca3d01299d8fe0e360302606aae8cc37f5e117d833aac4637493d589be19e100f8ac61a6172854c81e5111fef346
7
- data.tar.gz: 8d7f4a377314bfdb0d150eb1983dd6b84898aa78772a0b02b29539708ad3e8cd5852dbcb8f31a086b30d151a8a130f7b5300915064d7e58410686ed277249e07
6
+ metadata.gz: 8c32818ecac8fae55ac908bcf37a7d22d96a5c7e16780e045e0d43a815359c48b4005ebf0af96eac9c96f360a1a315f7717a77d6f6e1b36afef26b30e86c2f31
7
+ data.tar.gz: 7fb572c02cdb14106ea210db640e6bfca0a7a31197bebb0aadcc6dae901fbc1f3695ce29c2a11ac8c802f8651f66fef0d1f2562477cc9661b25494235ad051f9
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,3 +1,3 @@
1
1
  module MacAddr
2
- VERSION = "1.8.3".freeze
2
+ VERSION = "1.8.4".freeze
3
3
  end
data/lib/macaddr.rb CHANGED
@@ -33,44 +33,52 @@ module Mac
33
33
 
34
34
  # @return [Array<Ifaddr>] Return all interface Ifaddrs
35
35
  def ifaddrs
36
- return [] if !Socket.respond_to?(:getifaddrs) || INTERFACE_PACKET_FAMILY.nil?
37
- Socket.getifaddrs.select { |iface| iface.addr && iface.addr.pfamily == INTERFACE_PACKET_FAMILY }
36
+ return [] if !Socket.respond_to?(:getifaddrs) || iface_packet_family.nil?
37
+ Socket.getifaddrs.select { |iface| iface.addr && iface.addr.pfamily == iface_packet_family }
38
38
  end
39
39
 
40
40
  # @return [Hash<String,[String,nil]>]
41
41
  # all interfaces as keys, values are MAC addresses ((if present)
42
42
  def iface_macs
43
43
  h = iface_macs_raw.map do |k, v|
44
- v = nil if v.empty? || v !~ EXACT_MAC_REGEX || v =~ EMPTY_MAC
44
+ v = nil unless valid_mac? v
45
45
  [k, v]
46
46
  end
47
47
  Hash[h]
48
48
  end
49
49
 
50
- INTERFACE_PACKET_FAMILY = [:PF_LINK, :PF_PACKET].map { |c| Socket.const_defined?(c) && Socket.const_get(c) }.first
51
50
  EMPTY_MAC = /00(?:[^\h]?00){5}(?:[^\h]?00){2}?/.freeze
52
51
  HWADDR_REGEX = /hwaddr=([\h:]+)/.freeze
53
52
  WINDOWS_REGEX = /win(32|dows|ce)|(ms|cyg|bcc)win|mingw32|djgpp/i.freeze
54
- WINDOWS = RbConfig::CONFIG["host_os"] =~ WINDOWS_REGEX || RUBY_PLATFORM =~ WINDOWS_REGEX || ENV['OS'] == 'Windows_NT'
55
53
  # EUI48 and EUI64
56
54
  LOOSE_MAC_REGEX = /\h\h(?:[^\h]\h\h){5}(?:[^\h]\h\h){2}?/.freeze
57
55
  EXACT_MAC_REGEX = /\A#{LOOSE_MAC_REGEX}\z/.freeze
58
56
 
59
-
60
57
  private
61
58
 
59
+ def valid_mac?(s)
60
+ !s.nil? && !s.empty? && s =~ EXACT_MAC_REGEX && s != EMPTY_MAC
61
+ end
62
+
63
+ def windows?
64
+ @windows ||= RbConfig::CONFIG["host_os"] =~ WINDOWS_REGEX || RUBY_PLATFORM =~ WINDOWS_REGEX || ENV['OS'] == 'Windows_NT'
65
+ end
66
+
67
+ def iface_packet_family
68
+ @iface_packet_family ||= (Socket::PF_LINK if defined? Socket::PF_LINK) || (Socket::PF_PACKET if defined? Socket::PF_PACKET)
69
+ end
70
+
62
71
  def iface_macs_raw
63
- if Socket.const_defined? :PF_LINK
72
+ if defined? Socket::PF_LINK
64
73
  from_getnameinfo
65
- elsif Socket.const_defined? :PF_PACKET
74
+ elsif defined? Socket::PF_PACKET
66
75
  from_inspect_sockaddr
67
- elsif WINDOWS
76
+ elsif windows?
68
77
  for_windows
69
78
  else
70
79
  from_ifconfig
71
80
  end
72
81
  end
73
-
74
82
 
75
83
  def for_windows
76
84
  from_ipconfig || from_getmac
@@ -140,6 +148,6 @@ module Mac
140
148
  def from_inspect_sockaddr
141
149
  ifaddrs.map { |iface| mac = iface.addr.inspect_sockaddr[HWADDR_REGEX, 1]; [iface.name, mac] }
142
150
  end
143
- end
151
+ end # Mac
144
152
 
145
153
  MacAddr = Macaddr = Mac
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: macaddr-steakknife
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.3
4
+ version: 1.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ara T. Howard
metadata.gz.sig CHANGED
Binary file