Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: add support for interface broadcast addresses #23438

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/api/os.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ The properties available on the assigned network address object include:

* `address` {string} The assigned IPv4 or IPv6 address
* `netmask` {string} The IPv4 or IPv6 network mask
* `broadcast` {string} The IPv4 or IPv6 broadcast address (not available on all interface types)
* `family` {string} Either `IPv4` or `IPv6`
* `mac` {string} The MAC address of the network interface
* `internal` {boolean} `true` if the network interface is a loopback or
Expand Down Expand Up @@ -326,6 +327,7 @@ The properties available on the assigned network address object include:
{
address: '192.168.1.108',
netmask: '255.255.255.0',
broadcast: '192.168.1.255',
family: 'IPv4',
mac: '01:02:03:0a:0b:0c',
internal: false,
Expand Down
1 change: 1 addition & 0 deletions doc/api/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ is provided below for reference.
"mac": "13:10:de:ad:be:ef",
"address": "10.0.0.37",
"netmask": "255.255.255.0",
"broadcast": "10.0.0.255",
"family": "IPv4"
}
],
Expand Down
1 change: 1 addition & 0 deletions src/env_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
V(base_string, "base") \
V(bits_string, "bits") \
V(block_list_string, "blockList") \
V(broadcast_string, "broadcast") \
V(buffer_string, "buffer") \
V(bytes_parsed_string, "bytesParsed") \
V(bytes_read_string, "bytesRead") \
Expand Down
6 changes: 6 additions & 0 deletions src/node_os.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
int count, i;
char ip[INET6_ADDRSTRLEN];
char netmask[INET6_ADDRSTRLEN];
#if UV_VERSION_MAJOR >= 2
char broadcast[INET6_ADDRSTRLEN];
#endif
std::array<char, 18> mac;
Local<String> name, family;

Expand Down Expand Up @@ -218,6 +221,9 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
if (interfaces[i].address.address4.sin_family == AF_INET) {
uv_ip4_name(&interfaces[i].address.address4, ip, sizeof(ip));
uv_ip4_name(&interfaces[i].netmask.netmask4, netmask, sizeof(netmask));
#if UV_VERSION_MAJOR >= 2
uv_ip4_name(&interfaces[i].broadcast.broadcast4, broadcast, sizeof(broadcast));
#endif
family = env->ipv4_string();
} else if (interfaces[i].address.address4.sin_family == AF_INET6) {
uv_ip6_name(&interfaces[i].address.address6, ip, sizeof(ip));
Expand Down