Skip to content

Commit

Permalink
ipv4ToInt32 should return unsigned integer (#106)
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
peter23 authored Dec 13, 2024
1 parent a2a06d9 commit 5094ebb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/common/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5094ebb

Please sign in to comment.