Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the Shared Address Space #106

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/ip.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ ip.isPrivate = function(addr) {
/^::$/.test(addr);
};

ip.isShared = function(addr) {
return /^(::f{4}:)?100\.64\.([0-9]{1,3})\.([0-9]{1,3})$/i
.test(addr);
};

ip.isPublic = function(addr) {
return !ip.isPrivate(addr);
};
Expand Down
10 changes: 10 additions & 0 deletions test/api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,16 @@ describe('IP library for node.js', function() {
});
});

describe('isShared() method', function() {
it('should check if an address is in the shared address space', function() {
assert.equal(ip.isShared('100.64.0.1'), true);
});

it('should not detect 100.* as the shared address space', function() {
assert.equal(ip.isShared('100.6.0.1'), false);
});
});

describe('loopback() method', function() {
describe('undefined', function() {
it('should respond with 127.0.0.1', function() {
Expand Down