From 5094ebb7340ebe4830c4f4dac2e234267f2568aa Mon Sep 17 00:00:00 2001 From: peter23 Date: Fri, 13 Dec 2024 23:21:27 +0200 Subject: [PATCH] ipv4ToInt32 should return unsigned integer (#106) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At least ā€ˇSocksClient.createUDPFrame expects that: `buff.writeUInt32BE(ipv4ToInt32(options.remoteHost.host))`. `>>> 0` is fast and easy way to make integer unsigned: `[200,200,200,200].reduce((acc, part) => (acc << 8) + part, 0)` `-926365496` `[200,200,200,200].reduce((acc, part) => (acc << 8) + part, 0) >>> 0` `3368601800` --- src/common/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/helpers.ts b/src/common/helpers.ts index fc13fb7..8128604 100644 --- a/src/common/helpers.ts +++ b/src/common/helpers.ts @@ -214,7 +214,7 @@ export {validateSocksClientOptions, validateSocksClientChainOptions}; export function ipv4ToInt32(ip: string): number { const address = new Address4(ip); // Convert the IPv4 address parts to an integer - return address.toArray().reduce((acc, part) => (acc << 8) + part, 0); + return address.toArray().reduce((acc, part) => (acc << 8) + part, 0) >>> 0; } export function int32ToIpv4(int32: number): string {