2

I have a simple C program that binds a socket so that it can receive and send UDP packets. It uses recvfrom to receive packets, and shortly after receiving one, it constructs and sends a reply packet, using sendto in the obvious way, sending to the same address and port that recvfrom reported.

This program worked perfectly in initial testing, when the packets were coming in and going out over a regular Ethernet interface, eth0. But now I'm trying to use it over a PPP interface, ppp0, and for some reason it's not working.

sendto is not reporting any errors, but tcpdump is not showing the packets going out. (It is showing the packets coming in, so I'm pretty sure tcpdump is working.)

And I have an existing program that's doing essentially the same thing, but it works properly under all circumstances, on all interfaces. I haven't yet worked out how the existing program might be setting up its sockets or its send/receive logic differently, that allows it to work while my new, simpler program fails.

Some of the packets are large (approaching MTU), but plenty of them are small (<100 bytes), and none of them are getting through, so I don't think it's an MTU problem.

Can anyone think of anything that would cause a sent packet to fail to go out in this way? (I'm not saying it has anything to do with ppp in particular; that it fails under ppp for me may be a coincidence, or it may be a key part of the problem.)

Sorry I can't post the actual code; it's at work and I'm at home. The relevant part looks something like this:

struct sockaddr_in addr;
socklen_t addrlen = sizeof(addr);
char buf[1600];
int r, r2;

r = recvfrom(sock, buf, sizeof(buf), 0, (struct sockaddr *)&addr, &addrlen);

/* ... */

r2 = sendto(sock, buf2, n2, 0, (struct sockaddr *)&addr, addrlen);

(If you need to see a more complete example, I can post that tomorrow.)

Steve Summit
  • 45,437
  • 7
  • 70
  • 103

1 Answers1

0

If none of traffic works:

There could be routing problem. Check routing table of the host.

You can also check with tcpdump, that traffic is not going out via wrong interface. For example:

If you expect to see traffic in ppp0 by command:

tcpdump -i ppp0 udp port 123

And you don't see the wanted traffic, then check other interfaces by similar command to ensure that traffic does not go out via wrong interface:

tcpdump -i eth0 udp port 123

If part of traffic works:

If you are using some mobile network (often used via ppp0), then your uplink speed may be slower than downlink speed.

So a client may send more traffic to your server (via downlink), than uplink is capable to transfer.

Because UDP doesn't have such reliability and congestion/flow control like TCP have, UDP can discard some packets in overload situation.

SKi
  • 8,007
  • 2
  • 26
  • 57
  • Thanks for the suggestions. What do you mean using tcpdump to check interface usage? I'm not familiar with that technique. – Steve Summit May 17 '18 at 11:58
  • @Steve Summit : Example added to the answer. Nothing magical, maybe you have already done that. – SKi May 22 '18 at 11:46