MCPcopy
hub / github.com/nodejs/undici / parseAddress

Function parseAddress

lib/core/socks5-utils.js:12–40  ·  view source on GitHub ↗

* Parse an address and determine its type * @param {string} address - The address to parse * @returns {{type: number, buffer: Buffer}} Address type and buffer

(address)

Source from the content-addressed store, hash-verified

10 * @returns {{type: number, buffer: Buffer}} Address type and buffer
11 */
12function parseAddress (address) {
13 // Check if it's an IPv4 address
14 if (net.isIPv4(address)) {
15 const parts = address.split('.').map(Number)
16 return {
17 type: 0x01, // IPv4
18 buffer: Buffer.from(parts)
19 }
20 }
21
22 // Check if it's an IPv6 address
23 if (net.isIPv6(address)) {
24 return {
25 type: 0x04, // IPv6
26 buffer: parseIPv6(address)
27 }
28 }
29
30 // Otherwise, treat as domain name
31 const domainBuffer = Buffer.from(address, 'utf8')
32 if (domainBuffer.length > 255) {
33 throw new InvalidArgumentError('Domain name too long (max 255 bytes)')
34 }
35
36 return {
37 type: 0x03, // Domain
38 buffer: Buffer.concat([Buffer.from([domainBuffer.length]), domainBuffer])
39 }
40}
41
42/**
43 * Parse IPv6 address to buffer

Callers 2

buildConnectRequestMethod · 0.85
socks5-utils.jsFile · 0.85

Calls 2

parseIPv6Function · 0.85
mapMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…