Skip to content

Commit 5094ebb

Browse files
authored
ipv4ToInt32 should return unsigned integer (#106)
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`
1 parent a2a06d9 commit 5094ebb

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/common/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export {validateSocksClientOptions, validateSocksClientChainOptions};
214214
export function ipv4ToInt32(ip: string): number {
215215
const address = new Address4(ip);
216216
// Convert the IPv4 address parts to an integer
217-
return address.toArray().reduce((acc, part) => (acc << 8) + part, 0);
217+
return address.toArray().reduce((acc, part) => (acc << 8) + part, 0) >>> 0;
218218
}
219219

220220
export function int32ToIpv4(int32: number): string {

0 commit comments

Comments
 (0)