[英]How to know target address and port when receiving a UDP packet with libuv?
uvlib
UDP accepts event callback function of the following type: uvlib
UDP接受以下类型的事件回调函数:
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
. 没有关于目标端口和地址的信息,例如
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
套接字在0.0.0.0:xxxx上侦听
IP_PKTINFO具有此类信息,但是libuv没有公开启用它的API。
Yes, @Inaki right. 是的,@ Inaki对。 I found issues in
node.js
repository. 我在
node.js
存储库中发现了问题 。 They are active for years. 他们活跃了多年。 This feature request is still unresolved because of portability problems.
由于可移植性问题,此功能请求仍未解决。
multicast
-> bind to multicast address. multicast
->绑定到多播地址。 unicast
-> bind to concrete local interface, 1 interface - 1 socket. unicast
->绑定到具体的本地接口,1个接口-1个套接字。 But keep in mind going this way dynamic addresses could become pitfalls 快速搜索显示了一个类似的问题: 获取接收到的UDP数据包的目标地址您可以直接调用系统的API来获取信息,而无需绑定到特定地址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.