Skip to content

Commit f31d286

Browse files
committed
Added README.md; fixed typos; removed edundant type declarations
1 parent 1755c02 commit f31d286

File tree

3 files changed

+50
-46
lines changed

3 files changed

+50
-46
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
go-cidr
2+
=======
3+
Go library for various manipulations of CIDR netmasks and their associated addresses
4+

cidr/cidr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func PreviousSubnet(network *net.IPNet, prefixLen int) (*net.IPNet, bool) {
162162

163163
// NextSubnet returns the next available subnet of the desired mask size
164164
// starting for the maximum IP of the offset subnet
165-
// If the IP exceeds the maxium IP then the second return value is true
165+
// If the IP exceeds the maximum IP then the second return value is true
166166
func NextSubnet(network *net.IPNet, prefixLen int) (*net.IPNet, bool) {
167167
_, currentLast := AddressRange(network)
168168
mask := net.CIDRMask(prefixLen, 8*len(currentLast))

cidr/cidr_test.go

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,55 +18,55 @@ func TestSubnet(t *testing.T) {
1818
}
1919

2020
cases := []Case{
21-
Case{
21+
{
2222
Base: "192.168.2.0/20",
2323
Bits: 4,
2424
Num: 6,
2525
Output: "192.168.6.0/24",
2626
},
27-
Case{
27+
{
2828
Base: "192.168.2.0/20",
2929
Bits: 4,
3030
Num: 0,
3131
Output: "192.168.0.0/24",
3232
},
33-
Case{
33+
{
3434
Base: "192.168.0.0/31",
3535
Bits: 1,
3636
Num: 1,
3737
Output: "192.168.0.1/32",
3838
},
39-
Case{
39+
{
4040
Base: "192.168.0.0/21",
4141
Bits: 4,
4242
Num: 7,
4343
Output: "192.168.3.128/25",
4444
},
45-
Case{
45+
{
4646
Base: "fe80::/48",
4747
Bits: 16,
4848
Num: 6,
4949
Output: "fe80:0:0:6::/64",
5050
},
51-
Case{
51+
{
5252
Base: "fe80::/49",
5353
Bits: 16,
5454
Num: 7,
5555
Output: "fe80:0:0:3:8000::/65",
5656
},
57-
Case{
57+
{
5858
Base: "192.168.2.0/31",
5959
Bits: 2,
6060
Num: 0,
6161
Error: true, // not enough bits to expand into
6262
},
63-
Case{
63+
{
6464
Base: "fe80::/126",
6565
Bits: 4,
6666
Num: 0,
6767
Error: true, // not enough bits to expand into
6868
},
69-
Case{
69+
{
7070
Base: "192.168.2.0/24",
7171
Bits: 4,
7272
Num: 16,
@@ -104,40 +104,40 @@ func TestHost(t *testing.T) {
104104
}
105105

106106
cases := []Case{
107-
Case{
107+
{
108108
Range: "192.168.2.0/20",
109109
Num: 6,
110110
Output: "192.168.0.6",
111111
},
112-
Case{
112+
{
113113
Range: "192.168.0.0/20",
114114
Num: 257,
115115
Output: "192.168.1.1",
116116
},
117-
Case{
117+
{
118118
Range: "2001:db8::/32",
119119
Num: 1,
120120
Output: "2001:db8::1",
121121
},
122-
Case{
122+
{
123123
Range: "192.168.1.0/24",
124124
Num: 256,
125125
Error: true, // only 0-255 will fit in 8 bits
126126
},
127-
Case{
127+
{
128128
Range: "192.168.0.0/30",
129129
Num: -3,
130130
Output: "192.168.0.1", // 4 address (0-3) in 2 bits; 3rd from end = 1
131131
},
132-
Case{
132+
{
133133
Range: "192.168.0.0/30",
134134
Num: -4,
135135
Output: "192.168.0.0", // 4 address (0-3) in 2 bits; 4th from end = 0
136136
},
137-
Case{
137+
{
138138
Range: "192.168.0.0/30",
139139
Num: -5,
140-
Error: true, // 4 address (0-3) in 2 bits; cannot accomodate 5
140+
Error: true, // 4 address (0-3) in 2 bits; cannot accommodate 5
141141
},
142142
}
143143

@@ -170,17 +170,17 @@ func TestAddressRange(t *testing.T) {
170170
}
171171

172172
cases := []Case{
173-
Case{
173+
{
174174
Range: "192.168.0.0/16",
175175
First: "192.168.0.0",
176176
Last: "192.168.255.255",
177177
},
178-
Case{
178+
{
179179
Range: "192.168.0.0/17",
180180
First: "192.168.0.0",
181181
Last: "192.168.127.255",
182182
},
183-
Case{
183+
{
184184
Range: "fe80::/64",
185185
First: "fe80::",
186186
Last: "fe80::ffff:ffff:ffff:ffff",
@@ -210,39 +210,39 @@ func TestAddressCount(t *testing.T) {
210210
}
211211

212212
cases := []Case{
213-
Case{
213+
{
214214
Range: "192.168.0.0/16",
215215
Count: 65536,
216216
},
217-
Case{
217+
{
218218
Range: "192.168.0.0/17",
219219
Count: 32768,
220220
},
221-
Case{
221+
{
222222
Range: "192.168.0.0/32",
223223
Count: 1,
224224
},
225-
Case{
225+
{
226226
Range: "192.168.0.0/31",
227227
Count: 2,
228228
},
229-
Case{
229+
{
230230
Range: "0.0.0.0/0",
231231
Count: 4294967296,
232232
},
233-
Case{
233+
{
234234
Range: "0.0.0.0/1",
235235
Count: 2147483648,
236236
},
237-
Case{
237+
{
238238
Range: "::/65",
239239
Count: 9223372036854775808,
240240
},
241-
Case{
241+
{
242242
Range: "::/128",
243243
Count: 1,
244244
},
245-
Case{
245+
{
246246
Range: "::/127",
247247
Count: 2,
248248
},
@@ -262,13 +262,13 @@ func TestAddressCount(t *testing.T) {
262262
func TestIncDec(t *testing.T) {
263263

264264
testCase := [][]string{
265-
[]string{"0.0.0.0", "0.0.0.1"},
266-
[]string{"10.0.0.0", "10.0.0.1"},
267-
[]string{"9.255.255.255", "10.0.0.0"},
268-
[]string{"255.255.255.255", "0.0.0.0"},
269-
[]string{"::", "::1"},
270-
[]string{"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", "::"},
271-
[]string{"2001:db8:c001:ba00::", "2001:db8:c001:ba00::1"},
265+
{"0.0.0.0", "0.0.0.1"},
266+
{"10.0.0.0", "10.0.0.1"},
267+
{"9.255.255.255", "10.0.0.0"},
268+
{"255.255.255.255", "0.0.0.0"},
269+
{"::", "::1"},
270+
{"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", "::"},
271+
{"2001:db8:c001:ba00::", "2001:db8:c001:ba00::1"},
272272
}
273273

274274
for _, tc := range testCase {
@@ -300,11 +300,11 @@ func TestIncDec(t *testing.T) {
300300
func TestPreviousSubnet(t *testing.T) {
301301

302302
testCases := [][]string{
303-
[]string{"10.0.0.0/24", "9.255.255.0/24", "false"},
304-
[]string{"100.0.0.0/26", "99.255.255.192/26", "false"},
305-
[]string{"0.0.0.0/26", "255.255.255.192/26", "true"},
306-
[]string{"2001:db8:e000::/36", "2001:db8:d000::/36", "false"},
307-
[]string{"::/64", "ffff:ffff:ffff:ffff::/64", "true"},
303+
{"10.0.0.0/24", "9.255.255.0/24", "false"},
304+
{"100.0.0.0/26", "99.255.255.192/26", "false"},
305+
{"0.0.0.0/26", "255.255.255.192/26", "true"},
306+
{"2001:db8:e000::/36", "2001:db8:d000::/36", "false"},
307+
{"::/64", "ffff:ffff:ffff:ffff::/64", "true"},
308308
}
309309
for _, tc := range testCases {
310310
_, c1, _ := net.ParseCIDR(tc[0])
@@ -352,7 +352,7 @@ func TestVerifyNetowrk(t *testing.T) {
352352
}
353353

354354
testCases := []*testVerifyNetwork{
355-
&testVerifyNetwork{
355+
{
356356
CIDRBlock: "192.168.8.0/21",
357357
CIDRList: []string{
358358
"192.168.8.0/24",
@@ -371,7 +371,7 @@ func TestVerifyNetowrk(t *testing.T) {
371371
},
372372
}
373373
failCases := []*testVerifyNetwork{
374-
&testVerifyNetwork{
374+
{
375375
CIDRBlock: "192.168.8.0/21",
376376
CIDRList: []string{
377377
"192.168.8.0/24",
@@ -384,7 +384,7 @@ func TestVerifyNetowrk(t *testing.T) {
384384
"192.168.12.128/26",
385385
},
386386
},
387-
&testVerifyNetwork{
387+
{
388388
CIDRBlock: "192.168.8.0/21",
389389
CIDRList: []string{
390390
"192.168.7.0/24",
@@ -397,7 +397,7 @@ func TestVerifyNetowrk(t *testing.T) {
397397
"192.168.12.128/26",
398398
},
399399
},
400-
&testVerifyNetwork{
400+
{
401401
CIDRBlock: "10.42.0.0/24",
402402
CIDRList: []string{
403403

0 commit comments

Comments
 (0)