Repository navigation
Missing a way to get local IP address for received UDP message #1649
Description
Activity
- addeddgramIssues and PRs related to UDP and the dgram module.Issues and PRs related to UDP and the dgram module.feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.
on May 7, 2015 Also nodejs/node-v0.x-archive#6589. There are valid use cases and I think it would make a good addition.
However, different platforms have different quirks and there may be performance implications to consider. It's not really clear to me what the best way forward is.
I just encountered this issues when working on a multicast receiver, which is a slightly different case.Essentially, it is impossible to only receive packets on a specific multicast address when the port number is otherwise used on the host.Process 1 registers and listens to traffic for239.254.1.1:1234.Process 2 registers and listens to traffic for239.254.1.2:1234.
Now both will have bound to port1234and receive all packets on that interface.To fix this, we need to filter on the destination address, either manually using an exposed destination property, or through a new bind option.Edit: My issue can be fixed by binding to the multicast address.
This would be helpful for my ICE agent since I need to create sockets for each address accessible from the network. I have to do some funky iteration through
os.networkInterfacesand also can't seem to bind to specific ipv6 addresses.- addedlibuvIssues and PRs related to the libuv dependency or the uv binding.Issues and PRs related to the libuv dependency or the uv binding.help wantedIssues that need assistance from volunteers or PRs that need help to proceed.Issues that need assistance from volunteers or PRs that need help to proceed.
on Jun 8, 2016 - addedstalledIssues and PRs manually marked as stalled and scheduled for automatic closure.Issues and PRs manually marked as stalled and scheduled for automatic closure.
on Jul 7, 2017 6 remaining items
- added a commit that references this issue
on Jun 25, 2020 - added a commit that references this issue
on Jul 21, 2020 - added a commit that references this issue
on Jul 23, 2020 - added a commit that references this issue
on Jul 27, 2020 - added a commit that references this issue
on Sep 22, 2020 If I see it correctly, this issue has not really been resolved yet, right?
It's never been implemented because of irreconcilable platform differences. The last attempt was almost 10 years ago but I don't think the situation has materially improved.
I see, thank you for your feedback on this! Since the issue remains unresolved, would make it sense to reopen it, though..?
Only if there is some way forward but that's not the case here. If it can't be made to work, it can't be made to work.
For broadcast UDP messages I just listened on the broadcast address of each subnet of each interface. Don't listen on 255.255.255.255.
This should work for unicast too (by listening on specific addresses).
Normally you won't find two interfaces with overlapping subnets. If you do, then problably it has something to do with those platform differences and you surely already have bigger problems like NodeJS not allowing binding/restricting the socket to a specific interface.
So, in short, you shouldn't need Node telling you the destination IP address of the received packet, you can figure it out.
Also, by listening on specific broadcast addresses and specific IPs you can automatically rule out interfaces you're not suposed to listen on. A big security plus as a default.
This is a duplicate of nodejs/node-v0.x-archive#8788
Basically: I have a udp server listening on a port on multiple interfaces - when I get a message on this port, I would like to be able to detect what interface the message was received from.