1

uvlib UDP accepts event callback function of the following type:

typedef void (*uv_udp_recv_cb)(uv_udp_t* handle,
                               ssize_t nread,
                               const uv_buf_t* buf,
                               const struct sockaddr* addr,
                               unsigned flags);

There is no info about target port and address like sent_to_addr. Is there way to achieve it?

I need this to know on what interface packet received, or to know multicast group. Socket listens on 0.0.0.0:xxxx

kyb
  • 7,233
  • 5
  • 52
  • 105

3 Answers3

2

IP_PKTINFO has such a information, but libuv does not expose an API that enables it.

0

Yes, @Inaki right. I found issues in node.js repository. They are active for years. This feature request is still unresolved because of portability problems.

There are workarounds:

  1. for multicast -> bind to multicast address.
  2. for unicast -> bind to concrete local interface, 1 interface - 1 socket. But keep in mind going this way dynamic addresses could become pitfalls
kyb
  • 7,233
  • 5
  • 52
  • 105
0

A quick search shows a similar question: Get destination address of a received UDP packet You can directly invoke system's API to get the info, don't need to bind to the specific address.

Community
  • 1
  • 1
user2760751
  • 343
  • 2
  • 4
  • I have read that. Going around `libuv` violates portability! But in particular case it could be useful. – kyb Nov 22 '16 at 08:16