1
votes

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

3

3 Answers

2
votes

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

0
votes

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
0
votes

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.