wikk_ipv4 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4777a6c555cb227258c37530ce246e908080cdf6e8bc2eb399fb84eb08fca280
4
+ data.tar.gz: 9f0831860c41ccf98bfac61c6fbd7d5583c91fdfb50358145682d520a9a32c1f
5
+ SHA512:
6
+ metadata.gz: 2a5a65ec6413b493f11e1100065f124e88de3614b16b995583e72cc5fd1ac3ce6f4a32a01f85af99de4dbb71a4808b13696df3b56e1f7f316896f53d4c59b2bd
7
+ data.tar.gz: 3f8ada255ebd744c7d1afd074f1f31b60c71863a865ddbcc4b52cef52c3a15a1c849fd09454a928dca78aa75e1f513909ed12e01843ef448d13a53941c07fc05
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ robertburrowes Mon Jun 13 13:52:07 2022 +1200
2
+ rubocop
3
+ robertburrowes Mon Jun 13 13:45:19 2022 +1200
4
+ Creating a gem from ipv4 class we have been using.
data/Manifest.txt ADDED
@@ -0,0 +1,6 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.md
4
+ Rakefile
5
+ version
6
+ lib/wikk_ipv4.rb
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # wikk_ipv4
2
+
3
+ * Docs :: https://rbur004.github.io/wikk_ipv4/
4
+ * Source :: https://github.com/wikarekare/wikk_ipv4
5
+ * Gem :: https://rubygems.org/gems/wikk_ipv4
6
+
7
+ ## DESCRIPTION:
8
+
9
+ FIX (describe your package)
10
+
11
+ ## FEATURES/PROBLEMS:
12
+
13
+ * FIX (list of features or problems)
14
+
15
+ ## SYNOPSIS:
16
+
17
+ FIX (code sample of usage)
18
+
19
+ ## REQUIREMENTS:
20
+
21
+ * FIX (list of requirements)
22
+
23
+ ## INSTALL:
24
+
25
+ * FIX (sudo gem install, anything else)
26
+
27
+ ## LICENSE:
28
+
29
+ (The MIT License)
30
+
31
+ Copyright (c) 2022 FIX
32
+
33
+ Permission is hereby granted, free of charge, to any person obtaining
34
+ a copy of this software and associated documentation files (the
35
+ 'Software'), to deal in the Software without restriction, including
36
+ without limitation the rights to use, copy, modify, merge, publish,
37
+ distribute, sublicense, and/or sell copies of the Software, and to
38
+ permit persons to whom the Software is furnished to do so, subject to
39
+ the following conditions:
40
+
41
+ The above copyright notice and this permission notice shall be
42
+ included in all copies or substantial portions of the Software.
43
+
44
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
45
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
46
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
47
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
48
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
49
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
50
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ # -*- ruby -*-
2
+ require 'rubygems'
3
+ require 'hoe'
4
+ Hoe.plugin :yard
5
+ load "#{__dir__}/version"
6
+
7
+ Hoe.spec PROJECT do
8
+ self.readme_file = "README.md"
9
+ self.developer( "Rob Burrowes","r.burrowes@auckland.ac.nz")
10
+ remote_rdoc_dir = '' # Release to root
11
+
12
+ self.yard_title = PROJECT
13
+ self.yard_options = ['--markup', 'markdown', '--protected']
14
+ end
15
+
16
+
17
+ #Validate manfest.txt
18
+ #rake check_manifest
19
+
20
+ #Local checking. Creates pkg/
21
+ #rake gem
22
+
23
+ #create doc/
24
+ #rake docs
25
+
26
+ #Copy up to rubygem.org
27
+ #rake release VERSION=1.0.1
data/lib/wikk_ipv4.rb ADDED
@@ -0,0 +1,88 @@
1
+ # Stay in our own namespace
2
+ module WIKK
3
+ # Some utility IPv4 calles
4
+ class IPv4
5
+ VERSION = '0.0.1'
6
+
7
+ attr_reader :ip_address, :mask
8
+
9
+ def initialize(s, mask = 0xffffffff)
10
+ @mask = mask
11
+ if s.instance_of?(String)
12
+ ip = s.split(/\./)
13
+ (0..3).each { |i| ip[i] = '0' if ip[i].nil? }
14
+ @ip_address = ((ip[0].to_i << 24) | (ip[1].to_i << 16) | (ip[2].to_i << 8) | ip[3].to_i) & mask
15
+ elsif s
16
+ @ip_address = s & mask
17
+ else
18
+ @ip_address = nil
19
+ end
20
+ end
21
+
22
+ def ip_address=(value)
23
+ if value.instance_of?(String)
24
+ ip = s.split(/\./)
25
+ (0..3).each { |i| ip[i] = '0' if ip[i].nil? }
26
+ @ip_address = ((ip[0].to_i << 24) | (ip[1].to_i << 16) | (ip[2].to_i << 8) | ip[3].to_i) & mask
27
+ else
28
+ @ip_address = value
29
+ end
30
+ end
31
+
32
+ def to_s(mask = 0xffffffff)
33
+ if @ip_address
34
+ ip = (@ip_address & mask)
35
+ "#{(ip >> 24) & 255}.#{(ip >> 16) & 255}.#{(ip >> 8) & 255}.#{ip & 255}"
36
+ else
37
+ ''
38
+ end
39
+ end
40
+
41
+ def network(mask)
42
+ self.class.new(@ip_address, mask)
43
+ end
44
+
45
+ def broadcast(mask)
46
+ self.class.new(@ip_address & mask | ~mask)
47
+ end
48
+
49
+ def to_i
50
+ @ip_address
51
+ end
52
+
53
+ def self.mask_to_i(s)
54
+ ip = s.split(/\./)
55
+ ((ip[0].to_i << 24) | (ip[1].to_i << 16) | (ip[2].to_i << 8) | ip[3].to_i)
56
+ end
57
+
58
+ def self.maskbits_to_i(n)
59
+ 0xffffffff >> (32 - n) << (32 - n)
60
+ end
61
+
62
+ def +(other)
63
+ self.class.new(@ip_address + other)
64
+ end
65
+
66
+ def revptr(bytes)
67
+ rip = [ "#{@ip_address & 255}", "#{(@ip_address >> 8) & 255}", "#{(@ip_address >> 16) & 255}", "#{(@ip_address >> 24) & 255}" ]
68
+ rip[0, 4 - bytes].join('.')
69
+ end
70
+
71
+ def revnet(bytes)
72
+ rip = [ "#{@ip_address & 255}", "#{(@ip_address >> 8) & 255}", "#{(@ip_address >> 16) & 255}", "#{(@ip_address >> 24) & 255}" ]
73
+ rip[4 - bytes, bytes].join('.')
74
+ end
75
+
76
+ def ==(other)
77
+ @ip_address == other.ip_address
78
+ end
79
+
80
+ def notnil?
81
+ @ip_address != nil
82
+ end
83
+
84
+ def issubnet?(net)
85
+ (@ip_address & @mask) == (net.ip_address & @mask)
86
+ end
87
+ end
88
+ end
data/version ADDED
@@ -0,0 +1,2 @@
1
+ PROJECT="wikk_ipv4"
2
+ VERSION="0.0.1"
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wikk_ipv4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rob Burrowes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-06-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hoe-yard
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.3
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: hoe
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.23'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.23'
41
+ description: FIX (describe your package)
42
+ email:
43
+ - r.burrowes@auckland.ac.nz
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files:
47
+ - History.txt
48
+ - Manifest.txt
49
+ - README.md
50
+ files:
51
+ - History.txt
52
+ - Manifest.txt
53
+ - README.md
54
+ - Rakefile
55
+ - lib/wikk_ipv4.rb
56
+ - version
57
+ homepage: https://rbur004.github.io/wikk_ipv4/
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options:
63
+ - "--markup"
64
+ - markdown
65
+ - "--protected"
66
+ - "--title"
67
+ - wikk_ipv4
68
+ - "--quiet"
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubygems_version: 3.2.22
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: FIX (describe your package)
86
+ test_files: []