Manually send to iperf via UDP socket? (C++)

661 views Asked by At

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(). 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.

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

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).

Anyone have any ideas? Why isn't iperf noticing this connection?

**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. I print out the headers when received on machine A and B, and I don't see anything weird.

1

There are 1 answers

0
Ashkay On BEST ANSWER

Interesting. Turned out the problem was fixed by assigning the TUN device on machine A to eth0's IP address. 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.).

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.

If anyone has any further insights into how/why this works, I'd be very interested.