Class: InetAddress

types~InetAddress(buffer)

Represents an IP address.

Constructor

new InetAddress(buffer)

Creates an instance of InetAddress.

Parameters:
Name Type Description
buffer Buffer

The buffer containing the IPv4 or IPv6 address.

Source:
Throws:

If the buffer is not a valid IPv4 or IPv6 address.

Type
Error

Members

(readonly) buffer :Array

Immutable buffer that represents the IP address

Type:
  • Array
Source:

(readonly) length :Number

Returns the length of the underlying buffer

Type:
  • Number
Source:

(readonly) version :Number

Returns the Ip version (4 or 6)

Type:
  • Number
Source:

Methods

equals(other) → {Boolean}

Compares 2 addresses and returns true if the underlying bytes are the same

Parameters:
Name Type Description
other InetAddress
Source:
Returns:
Type
Boolean

getBuffer() → {Buffer}

Returns the underlying buffer

Source:
Returns:
Type
Buffer

(package) getInternal() → {rust.InetAddressWrapper}

Get the rust object.

Source:
Returns:
Type
rust.InetAddressWrapper

inspect() → {string}

Provide the name of the constructor and the string representation

Source:
Returns:
Type
string

toJSON() → {String}

Returns the string representation. Method used by the native JSON.stringify() to serialize this instance.

Source:
Returns:
Type
String

toString(encodingopt) → {String}

Returns the string representation of the IP address.

For v4 IP addresses, a string in the form of d.d.d.d is returned.

For v6 IP addresses, a string in the form of x:x:x:x:x:x:x:x is returned, where the 'x's are the hexadecimal values of the eight 16-bit pieces of the address, according to rfc5952. In cases where there is more than one field of only zeros, it can be shortened. For example, 2001:0db8:0:0:0:1:0:1 will be expressed as 2001:0db8::1:0:1.

Parameters:
Name Type Attributes Description
encoding String <optional>
Source:
Returns:
Type
String

(package, static) fromRust(rustInetAddress) → {InetAddress}

Get duration from rust object. Not intended to be exposed in the API

Parameters:
Name Type Description
rustInetAddress rust.InetAddressWrapper
Source:
Returns:
Type
InetAddress

(static) fromString(value) → {InetAddress}

Converts a string representation of an IP address to an InetAddress instance.

This function accepts both IPv4 and IPv6 addresses, which may include an embedded IPv4 address.

Parameters:
Name Type Description
value string
Source:
Throws:
  • If the input string is not a valid IPv4 or IPv6 address.
Type
TypeError
Returns:
Type
InetAddress