Skip to content

Commit

Permalink
os: expose broadcast address in os.networkInterfaces()
Browse files Browse the repository at this point in the history
Not using the correct broadcast address in applications can cause
disasterous results. Rather than letting the programmer guess at
the broadcast address and try to derive it correctly, allow him to
query the system instead for the correctly configured state.

Fixes: #23437
Depends-on: libuv/libuv#2033
  • Loading branch information
pprindeville committed Sep 24, 2024
1 parent ffe0dc5 commit dd745f2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
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
2 changes: 2 additions & 0 deletions src/node_os.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
int count, i;
char ip[INET6_ADDRSTRLEN];
char netmask[INET6_ADDRSTRLEN];
char broadcast[INET6_ADDRSTRLEN];
std::array<char, 18> mac;
Local<String> name, family;

Expand Down Expand Up @@ -218,6 +219,7 @@ 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));
uv_ip4_name(&interfaces[i].broadcast.broadcast4, broadcast, sizeof(broadcast));
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

0 comments on commit dd745f2

Please sign in to comment.