Skip to content

Commit 80a4ebe

Browse files
committed
convert ipv4 and ipv6 ip addresses to ipv6.v6.Address
1 parent d5516dc commit 80a4ebe

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

anon.coffee

+5-8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ address = (ip) ->
1515
i = new ipv6.v6.Address(ip)
1616
else
1717
i = new ipv6.v4.Address(ip)
18+
subnetMask = 96 + i.subnetMask
19+
ip = '::ffff:' + i.toV6Group() + "/" + subnetMask
20+
i = new ipv6.v6.Address(ip)
1821

1922
ipToInt = (ip) ->
2023
i = address(ip)
@@ -35,12 +38,6 @@ isIpInRange = (ip, block) ->
3538
else
3639
a = address(ip)
3740
b = address(block)
38-
# if we are comparing a v6 address to an v4 cidr range we need to
39-
# convert the v4 cidr to a v6 cidr
40-
if not a.v4 and b.v4
41-
subnetMask = 96 + b.subnetMask
42-
block = '::' + b.toV6Group() + "/" + subnetMask
43-
b = new ipv6.v6.Address(block)
4441
a.isInSubnet(b)
4542

4643
isIpInAnyRange = (ip, blocks) ->
@@ -61,7 +58,6 @@ loadJson = (path) ->
6158
require path
6259

6360
getStatusLength = (edit, name, template) ->
64-
# returns length of the tweet based on shortened url
6561
# https://support.twitter.com/articles/78124-posting-links-in-a-tweet
6662
fakeUrl = 'http://t.co/BzHLWr31Ce'
6763
status = Mustache.render template, name: name, url: fakeUrl, page: edit.page
@@ -118,7 +114,8 @@ main = ->
118114
if require.main == module
119115
main()
120116

121-
# export these for testing
117+
# for testing
118+
exports.address = address
122119
exports.compareIps = compareIps
123120
exports.isIpInRange = isIpInRange
124121
exports.isIpInAnyRange = isIpInAnyRange

0 commit comments

Comments
 (0)