diff options
author | Kris Shannon <k.shannon@amaze.com.au> | 2019-11-22 21:39:12 +1100 |
---|---|---|
committer | Kris Shannon <k.shannon@amaze.com.au> | 2019-11-22 21:39:12 +1100 |
commit | ae3930b699be1707d595743e77808548d98c0233 (patch) | |
tree | cbbe996144f46fb1a03baf784e24e33b31b69fc3 /lib/ohai/mixin | |
parent | 964903716867f6a1a09f4c6a3b270ef331c856c7 (diff) | |
download | ohai-ae3930b699be1707d595743e77808548d98c0233.tar.gz |
Extract `hex_to_dec_netmask` into mixin/network_helper.rb
Signed-off-by: Kris Shannon <k.shannon@amaze.com.au>
Diffstat (limited to 'lib/ohai/mixin')
-rw-r--r-- | lib/ohai/mixin/network_helper.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/ohai/mixin/network_helper.rb b/lib/ohai/mixin/network_helper.rb index b76f8033..be783722 100644 --- a/lib/ohai/mixin/network_helper.rb +++ b/lib/ohai/mixin/network_helper.rb @@ -24,6 +24,13 @@ module Ohai "inet" => "default", "inet6" => "default_inet6", }.freeze + + def hex_to_dec_netmask(netmask) + # example 'ffff0000' -> '255.255.0.0' + dec = netmask[0..1].to_i(16).to_s(10) + [2, 4, 6].each { |n| dec = dec + "." + netmask[n..n + 1].to_i(16).to_s(10) } + dec + end end end end |