Skip to content
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
11 changes: 11 additions & 0 deletions lib/ipv4.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,15 @@ Address4.prototype.binaryZeroPad = function () {
return padStart(this.bigInteger().toString(2), constants.BITS, '0');
};

/**
* Returns the ip representation of subnet mask
* @memberof Address4
* @instance
* @returns {string} subnetMaskIP
*/
Address4.prototype.subnetMaskIP = function () {
const shiftBits = constants.BITS - this.subnetMask;
return Address4.fromInteger(((0xffffffff << shiftBits) & 0xffffffff) >>> 0).correctForm()
};

module.exports = Address4;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"browser",
"validation"
],
"version": "6.2.0",
"version": "6.2.1",
"author": "Beau Gunderson <[email protected]> (https://beaugunderson.com/)",
"license": "MIT",
"main": "ip-address.js",
Expand Down
8 changes: 8 additions & 0 deletions test/functionality-v4-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,12 @@ describe('v4', function () {
});
});
});

describe('An IP with CIDR notation', function () {
var topic = new Address4('127.0.0.2/20');

it('should generate IP representation of subnet mask correctly', function () {
topic.subnetMaskIP().should.equal('255.255.240.0');
});
});
});