Skip to content

Undocumented change to "family" attribute in os.networkInterfaces() in Node 18 #42787

Closed
@BenSjoberg

Description

Version

v18.0.0

Platform

Darwin Bens-MacBook-Pro-2.local 21.4.0 Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64 x86_64

Subsystem

No response

What steps will reproduce the bug?

Easy to reproduce in the REPL - just call os.networkInterfaces() Each listed IP has a "family" attribute. Before Node 18 this was a string value of "IPv4" or "IPv6", in Node 18 it's a numeric 4 or 6.

How often does it reproduce? Is there a required condition?

Happens 100% of the time. Only requirement is to be running Node 18.

What is the expected behavior?

The family attribute should be either "IPv4" or "IPv6". The Node 18 documentation still describes it this way, and the Node 18 changelog doesn't mention this change, so my assumption is that this is unintended. If it actually was intended, then the documentation and changelog should be updated to reflect it.

What do you see instead?

Example from the Node 18 REPL:

> os.networkInterfaces()
{
  lo0: [
    {
      address: '127.0.0.1',
      netmask: '255.0.0.0',
      family: 4,
      mac: '00:00:00:00:00:00',
      internal: true,
      cidr: '127.0.0.1/8'
    },
    {
      address: '::1',
      netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
      family: 6,
      mac: '00:00:00:00:00:00',
      internal: true,
      cidr: '::1/128',
      scopeid: 0
    },
    ...
]

Additional information

The changelog does say "net: make server.address() return an integer for family". If this was unintentional, maybe it could be a side effect from whatever was done in that PR? (I haven't looked at that PR, nor am I familiar with Node's internals, so this is just a guess.)

Metadata

Assignees

No one assigned

    Labels

    osIssues and PRs related to the os subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions