diff --git a/lib/ipv4.js b/lib/ipv4.js index 3da9cfe7..477aa574 100644 --- a/lib/ipv4.js +++ b/lib/ipv4.js @@ -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; diff --git a/package.json b/package.json index 082a286f..cc62df93 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "browser", "validation" ], - "version": "6.2.0", + "version": "6.2.1", "author": "Beau Gunderson (https://beaugunderson.com/)", "license": "MIT", "main": "ip-address.js", diff --git a/test/functionality-v4-test.js b/test/functionality-v4-test.js index e560b793..7a740c73 100644 --- a/test/functionality-v4-test.js +++ b/test/functionality-v4-test.js @@ -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'); + }); + }); });