You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
We're porting C# code to NodeJS and found something is missing in the Node datagram API.
In C# we're using Socket.ReceiveMessageFrom to receive the datagram. In addition to the remote end point, we also get the IPPacketInformation which contains the destination address of the packet (== address of local interface that received the packet).
In C# we use this method to get connected with a 3rd party device:
we set up a UDP socket that's bound to IPAddress.Any
then we receive a discovery packet from the 3rd party device on one of the interfaces
we need to send back the local IP address of the interface where the packet arrived on, so the 3rd party device can initiate a TCP/IP connection to it.
Is there a way to achieve the same using the Node datagram API?
Thank you, indeed that's what I'm working on right now :) Its not supported in libuv yet, but if I'll push it to libuv's master - node 0.11 will eventually support it.
IP_PKTINFO is Linux-only, the BSDs use IP_RECVDSTADDR. Solaris has a IP_RECVDSTADDR flag too but I've never tried if it actually works. There's also IP_RECVOPTS which is quite portable - except it doesn't work on OS X.
At any rate, this should be an explicit opt-in because it impacts performance.
I have two interfaces on the same subnet (a real and a cluster address) and I need to send UDP replies from the address to which the original datagram was sent.
@chrisdew as far as I remember, it doesn't work well on OSX and probably on FreeBSD. You'll get better results by listening on two interfaces explicitly.
@indutny Listening on two interfaces explicitly does not negate needing IP_PKTINFO, at least when receiving udp multicast broadcast messages which you have to bind to INADDR_ANY or in6addr_any.
I have a working patch for IPv4 (IP_PKTINFO) and IPv6 (IPV6_RECVPKTINFO) for the 0.10.x stable branch (what I need for) but I haven't had a chance to test BSD yet, only Windows, Linux and OSX.
@mikinho Sorry, but we won't be able to land it in v0.10, the API is locked there.
As far as I understand your patch still won't work with dualstack sockets (or work only for incoming ipv6 udp packets), right? Feel free to submit it to https://github.com/joyent/libuv anyway.
Dual-Stack Sockets does work with the exception that if IPv4 is disabled then the setsockopt will fail. I could easily detect IPv4 being disabled on the system and use the appropriate flag to get around that but in my mind that should be up to the application using the API, not libuv. I've updated my patch to v0.11. I just did v0.10 since that is what I needed it for. I'll move the discussion elsewhere after submitting the patch, I hadn't noticed this was the node repo, I assumed it was the libuv.
Activity
indutny commentedon Nov 26, 2013
Looking.
huysentruitw commentedon Nov 26, 2013
Seems like socket option
IP_PKTINFOhas to be used for this in the underlying interface. See http://stackoverflow.com/questions/5281409/get-destination-address-of-a-received-udp-packet/5309155#5309155indutny commentedon Nov 26, 2013
Thank you, indeed that's what I'm working on right now :) Its not supported in libuv yet, but if I'll push it to libuv's master - node 0.11 will eventually support it.
huysentruitw commentedon Nov 26, 2013
Fantastic!
bnoordhuis commentedon Nov 26, 2013
IP_PKTINFO is Linux-only, the BSDs use IP_RECVDSTADDR. Solaris has a IP_RECVDSTADDR flag too but I've never tried if it actually works. There's also IP_RECVOPTS which is quite portable - except it doesn't work on OS X.
At any rate, this should be an explicit opt-in because it impacts performance.
indutny commentedon Nov 26, 2013
@bnoordhuis thanks, I figured it out. I'm going to add flag to
uv_udp_bind()and ansrcargument foruv_udp_recv_cb.indutny commentedon Nov 26, 2013
The bad news is that it doesn't work with dualstack on osx. I just can't set
IP_PKTINFOon ipv6 socket...indutny commentedon Nov 26, 2013
I stubbed out something, but not sure if I'm going to finish it, since it doesn't work well with dual-stack udp:
indutny commentedon Dec 12, 2013
@WouterHuysentruit sorry, I don't think I'm going to finish it. There're really unsolvable problems with dual-stack support. Closing it.
chrisdew commentedon May 16, 2014
@indutny This is an issue for me too.
I have two interfaces on the same subnet (a real and a cluster address) and I need to send UDP replies from the address to which the original datagram was sent.
Any chance of getting it reopened?
@WouterHuysentruit Did you find a work-around?
indutny commentedon May 16, 2014
@chrisdew as far as I remember, it doesn't work well on OSX and probably on FreeBSD. You'll get better results by listening on two interfaces explicitly.
chrisdew commentedon May 19, 2014
I've hacked around this issue by adding a custom route (with a defined 'src') when the cluster alias interface is brought up.
(Listening on interfaces explicitly is too complicated when those interface can come and go at runtime.)
mikinho commentedon Jul 2, 2014
@indutny Listening on two interfaces explicitly does not negate needing IP_PKTINFO, at least when receiving udp multicast broadcast messages which you have to bind to INADDR_ANY or in6addr_any.
I have a working patch for IPv4 (IP_PKTINFO) and IPv6 (IPV6_RECVPKTINFO) for the 0.10.x stable branch (what I need for) but I haven't had a chance to test BSD yet, only Windows, Linux and OSX.
Can you think of any other issues you had?
indutny commentedon Jul 2, 2014
@mikinho Sorry, but we won't be able to land it in v0.10, the API is locked there.
As far as I understand your patch still won't work with dualstack sockets (or work only for incoming ipv6 udp packets), right? Feel free to submit it to https://github.com/joyent/libuv anyway.
Thank you!
mikinho commentedon Jul 2, 2014
Dual-Stack Sockets does work with the exception that if IPv4 is disabled then the setsockopt will fail. I could easily detect IPv4 being disabled on the system and use the appropriate flag to get around that but in my mind that should be up to the application using the API, not libuv. I've updated my patch to v0.11. I just did v0.10 since that is what I needed it for. I'll move the discussion elsewhere after submitting the patch, I hadn't noticed this was the node repo, I assumed it was the libuv.
bushje commentedon Jul 18, 2014
@mikinho Hi there, Id like to give your patch a try if possible. Have you submitted it to the main node repo?
Many thanks.