Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
  • Loading branch information
liranmauda committed Feb 9, 2025
1 parent e8b684e commit f390b51
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 4 deletions.
1 change: 0 additions & 1 deletion src/test/unit_tests/jest_tests/test_net_utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ describe('IP Utils', () => {
expect(net_utils.ip_toString(Buffer.from([255, 255, 255, 255]), 0, 4)).toBe('255.255.255.255');
expect(net_utils.ip_toString(Buffer.from([32, 1, 13, 184, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]), 0, 16)).toBe('2001:db8::1');
expect(() => net_utils.ip_toString(Buffer.from([192, 168, 1, 1]), undefined, 4)).toThrow('Offset is required');
expect(() => net_utils.ip_toString(Buffer.from([192, 168, 1, 1]), 0, 3)).toThrow('Invalid IP length');
});

it('ipv4_to_buffer should convert IPv4 string to buffer', () => {
Expand Down
4 changes: 1 addition & 3 deletions src/util/net_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function ip_toString(buff, offset, length) {
length = length ?? (buff.length - offset);

if (length === 4) { // IPv4
return Array.from(buff.slice(offset, offset + length)).join('.');
return Array.from(buff.subarray(offset, offset + length)).join('.');
} else if (length === 16) { // IPv6
const result = [];
for (let i = 0; i < length; i += 2) {
Expand All @@ -85,8 +85,6 @@ function ip_toString(buff, offset, length) {
ipv6 = ipv6.replace(/:{3,4}/, '::');
return ipv6;
}

throw new Error('Invalid IP length');
}

/**
Expand Down

0 comments on commit f390b51

Please sign in to comment.