[英]Manually send to iperf via UDP socket? (C++)
I have a program that needs to measure total loss after routing through a machine.我有一个程序需要在通过机器路由后测量总损耗。
Essentially, I generate UDP traffic with iperf
on machine A that is destined for machine C. However, I first route this traffic through machine B**, then send it to machine C via a raw socket to port 5001 (the default port that iperf
listens to) with sendto()
.本质上,我在机器 A 上使用
iperf
生成发往机器 C 的 UDP 流量。但是,我首先通过机器 B** 路由此流量,然后通过原始套接字将其发送到机器 C 到端口 5001( iperf
的默认端口)用sendto()
收听sendto()
。 While running a tcpdump
shows that the packets are being received on machine C, the iperf
server doesn't see these connections or the packet.运行
tcpdump
显示数据包正在机器 C 上接收时, iperf
服务器没有看到这些连接或数据包。
I've hunted around the iperf
source code a bit to see how it works, and I see that packets are accepted with the function我已经搜索了
iperf
源代码以了解它是如何工作的,并且我看到该函数接受了数据包
rc = recvfrom( mSettings->mSock, mBuf, mSettings->mBufLen, 0,
(struct sockaddr*) &server->peer, &server->size_peer );.
Basically, because its simply a recvfrom
, I don't see why there's a problem if I'm very sure I'm not modifying the packets at any time, and am sending them with the function sendto(s, buf, len, 0, (struct sockaddr*) &si_other, slen)
and a socket(AF_INET, SOCK_RAW, IPPROTO_UDP)
.基本上,因为它只是一个
recvfrom
,如果我非常确定我不会在任何时候修改数据包,我不明白为什么会出现问题,并且正在使用函数sendto(s, buf, len, 0, (struct sockaddr*) &si_other, slen)
和一个socket(AF_INET, SOCK_RAW, IPPROTO_UDP)
。
Anyone have any ideas?谁有想法? Why isn't
iperf
noticing this connection?为什么
iperf
没有注意到这种联系?
**I actually route the packets to a TUN device on machine A, then read them from a userspace program on A, send them to B with a UDP socket, read them on a userspace program on B, then send them via a raw socket with IP_HDRINCL
disabled. **我实际上将数据包路由到机器 A 上的 TUN 设备,然后从 A 上的用户空间程序读取它们,使用 UDP 套接字将它们发送到 B,在 B 上的用户空间程序上读取它们,然后通过原始套接字发送它们禁用
IP_HDRINCL
。 I print out the headers when received on machine A and B, and I don't see anything weird.我在机器 A 和 B 上收到时打印出标题,我没有看到任何奇怪的东西。
Interesting.有趣的。 Turned out the problem was fixed by assigning the TUN device on machine A to
eth0
's IP address.原来问题是通过将机器 A 上的 TUN 设备分配给
eth0
的 IP 地址来解决的。 Before, I assigned the TUN device to it's own IP address (I did attempt to remove an IP address from the TUN device, but then it defaulted to eth1
. That didn't work either.).之前,我将 TUN 设备分配给它自己的 IP 地址(我确实尝试从 TUN 设备中删除一个 IP 地址,但后来它默认为
eth1
。这也不起作用。)。
I guess some modifications were occurring because of this, or that some sort of tunneling/connection wasn't established by iperf
because the packets weren't being sent out of eth0
before.我想因此发生了一些修改,或者
iperf
没有建立某种隧道/连接,因为数据包之前没有从eth0
发送出去。
If anyone has any further insights into how/why this works, I'd be very interested.如果有人对它的工作原理/原因有任何进一步的了解,我会非常感兴趣。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.