Skip to content

Commit

Permalink
parsing ipv4 mapped ip
Browse files Browse the repository at this point in the history
  • Loading branch information
ortexx committed Jan 30, 2023
1 parent 34516ee commit b5538c9
Show file tree
Hide file tree
Showing 5 changed files with 258 additions and 219 deletions.
11 changes: 8 additions & 3 deletions dist/ip-cidr.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,14 @@ IPCIDR.createAddress = function (val) {

val.match(/:.\./) && (val = val.split(':').pop());
const ipAddressType = val.match(":")? ipAddress.Address6: ipAddress.Address4;
let ip = new ipAddressType(val);

if(ipAddressType === ipAddress.Address4) {
const parts = val.split('.');
if(ip.v4 && val.match(":") && ip.address4) {
ip = ip.address4;
}

if(ip.v4) {
const parts = ip.addressMinusSuffix.split('.');

for(let i = 0; i < parts.length; i++) {
const part = parts[i].split('/')[0];
Expand All @@ -190,7 +195,7 @@ IPCIDR.createAddress = function (val) {
}
}

return new ipAddressType(val);
return ip
}

IPCIDR.isValidAddress = function (address) {
Expand Down
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,14 @@ IPCIDR.createAddress = function (val) {

val.match(/:.\./) && (val = val.split(':').pop());
const ipAddressType = val.match(":")? ipAddress.Address6: ipAddress.Address4;
let ip = new ipAddressType(val);

if(ipAddressType === ipAddress.Address4) {
const parts = val.split('.');
if(ip.v4 && val.match(":") && ip.address4) {
ip = ip.address4;
}

if(ip.v4) {
const parts = ip.addressMinusSuffix.split('.');

for(let i = 0; i < parts.length; i++) {
const part = parts[i].split('/')[0];
Expand All @@ -189,7 +194,7 @@ IPCIDR.createAddress = function (val) {
}
}

return new ipAddressType(val);
return ip
}

IPCIDR.isValidAddress = function (address) {
Expand Down
Loading

0 comments on commit b5538c9

Please sign in to comment.