From 82363d864d1a73f6227ba784e1af9c9d3dfe2816 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Thu, 25 Mar 2021 12:19:30 -0700 Subject: [PATCH] net: add SocketAddress class Signed-off-by: James M Snell PR-URL: https://github.com/nodejs/node/pull/37917 Reviewed-By: Matteo Collina --- doc/api/net.md | 45 ++++++++ doc/api/worker_threads.md | 1 + lib/internal/socketaddress.js | 153 ++++++++++++++++++++++++++++ lib/net.js | 6 ++ node.gyp | 1 + src/env.h | 2 + src/node_errors.h | 2 + src/node_sockaddr.cc | 143 ++++++++++++++++++++++++++ src/node_sockaddr.h | 54 ++++++++++ test/parallel/test-socketaddress.js | 113 ++++++++++++++++++++ 10 files changed, 520 insertions(+) create mode 100644 lib/internal/socketaddress.js create mode 100644 test/parallel/test-socketaddress.js diff --git a/doc/api/net.md b/doc/api/net.md index 6b0607d120461c..89c8bd5c80eb79 100644 --- a/doc/api/net.md +++ b/doc/api/net.md @@ -135,6 +135,51 @@ added: REPLACEME The list of rules added to the blocklist. +## Class: `net.SocketAddress` + +### `new net.SocketAddress([options])` + + +* `options` {Object} + * `address` {string} The network address as either an IPv4 or IPv6 string. + **Default**: `'127.0.0.1'` if `family` is `'ipv4'`; `'::'` if `family` is + `'ipv6'`. + * `family` {string} One of either `'ipv4'` or 'ipv6'`. **Default**: `'ipv4'`. + * `flowlabel` {number} An IPv6 flow-label used only if `family` is `'ipv6'`. + * `port` {number} An IP port. + +### `socketaddress.address` + + +* Type {string} + +### `socketaddress.family` + + +* Type {string} Either `'ipv4'` or `'ipv6'`. + +### `socketaddress.flowlabel` + + +* Type {number} + +### `socketaddress.port` + + +* Type {number} + ## Class: `net.Server`