pcap - 在同一台计算机上流式传输和接收 udp

发布于 2024-12-09 02:15:26 字数 416 浏览 7 评论 0原文

为了解释我想要得到什么,这是一个例子。 假设我们有一台带有一个网卡的 PC。它具有单个 IP 地址 172.16.0.1。 使用 VLC,我们启动到 172.16.0.1:1234 的 udp 流,然后启动 VLC 的另一个副本并连接到 udp://@172.16.0.1:1234。现在我们将看到我们的视频流。

如果运行嗅探器,您将在环回上看到从 172.16.0.1:some_random_port 到 172.16.0.1:1234 的数据包。我们的 NIC 上没有流量。

我想做的是在同一台计算机上传输和接收 udp,就像 VLC 那样。但主要问题是 pcap 只能 pcap_open() 一个真实的设备,它不能与环回一起工作。

有可能解决这个问题吗?

PS我使用的是Windows和WinPcap,与Linux版本不同,它可以发送数据包。

To explain what I would like to get, here's an example.
Let's say, we have a PC with one NIC. It has single IP address 172.16.0.1.
Using VLC, we start a udp stream to 172.16.0.1:1234, then launch another copy of VLC and connect to udp://@172.16.0.1:1234. Now we'll see our video streaming.

If you run sniffer, you will see packets from 172.16.0.1:some_random_port to 172.16.0.1:1234 on loopback. There's no trafic on our NIC.

What I want to do is to stream and receive udp in the same computer, like VLC does it. But the main problem is that pcap can only pcap_open() a real device, it can't work with loopback.

Is it possible to solve that problem?

P.S. I'm using Windows and WinPcap, unlike Linux version, it can send packets.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

々眼睛长脚气 2024-12-16 02:15:26

如果您只想发送和接收 UDP 数据包,我建议仅使用常规 Winsock 套接字,就像您在 UN*X 上使用常规套接字一样;使用 WinPcap 要求您重新实现 IP 和 UDP,并且不会让您在 Windows 下(或至少在某些版本的 UN*X 上)发送到同一台计算机上的另一个套接字。

如果您想观察您发送的流量,不幸的是 WinPcap 不会提供帮助,因为它依赖于从 NDIS 发送和接收的数据包(其驱动程序插入 NDIS),而这并不能解决问题。从一台机器上的一个套接字发送到同一台机器上的另一个套接字的数据包不会发生这种情况。

(顺便说一句,请注意,libpcap可以在 Linux 和 *BSD、Mac OS X、Solaris 和 Digital/Tru64 UNIX 上发送数据包,并且已经能够这样做好几年了;旧版本libpcap 不支持它,但过去几年可用的版本可以。但是,根据我的第一段,使用 libpcap 在这些操作系统上发送和接收常规 UDP 数据包是没有意义的,就像它所做的那样。没有意义在 Windows 上使用 WinPcap 来实现此目的。)

If you just want to send and receive UDP packets, I would suggest just using regular Winsock sockets, just as you'd use regular sockets on UN*X; using WinPcap requires that you re-implement IP and UDP, and won't let you send to another socket on the same machine under Windows (or on at least some versions of UN*X, either).

If you want to watch the traffic you're sending, unfortunately WinPcap won't help, as it relies on packets being sent out and received from NDIS (its driver plugs into NDIS), and that doesn't happen for packets sent from one socket on a machine to another socket on the same machine.

(Note, BTW, that libpcap can send packets on Linux and *BSD and Mac OS X and Solaris and Digital/Tru64 UNIX, for example, and has been able to do so for several years; older versions of libpcap didn't support it, but the versions available for the past few years can. However, as per my first paragraph, it would not make sense to use libpcap to send and receive regular UDP packets on those OSes, just as it makes no sense to use WinPcap for that purpose on Windows.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文