UdpClient receive on broadcast address

Here’s the jist of some code I am currently using in a production app that works (we’ve got a bit extra in there to handle the case where the client are server apps are running on a standalone installation). It’s job is to receive udp notifications that messages are ready for processing. As mentioned by … Read more

Problems with SO_BINDTODEVICE Linux socket option

I have been looking into this for a while after seeing conflicting answers to how SO_BINDTODEVICE is actually used. Some sources claim that the correct usage is to pass in a struct ifreq pointer, which has the device name and index obtained via an ioctl. For example: struct ifreq ifr; memset(&ifr, 0, sizeof(struct ifreq)); snprintf(ifr.ifr_name, … Read more

How to set the don’t fragment (DF) flag on a socket?

You do it with the setsockopt() call, by using the IP_DONTFRAG option: int val = 1; setsockopt(sd, IPPROTO_IP, IP_DONTFRAG, &val, sizeof(val)); Here’s a page explaining this in further detail. For Linux, it appears you have to use the IP_MTU_DISCOVER option with the value IP_PMTUDISC_DO (or IP_PMTUDISC_DONT to turn it off): int val = IP_PMTUDISC_DO; setsockopt(sd, … Read more

What would cause UDP packets to be dropped when being sent to localhost?

Overview What is causing the inability to send/receive data locally? Mostly buffer space. Imagine sending a constant 10MB/second while only able to consume 5MB/second. The operating system and network stack can’t keep up, so packets are dropped. (This differs from TCP, which provides flow control and re-transmission to handle such a situation.) Even when data … Read more

Size of empty UDP and TCP packet?

TCP: Size of Ethernet frame – 24 Bytes Size of IPv4 Header (without any options) – 20 bytes Size of TCP Header (without any options) – 20 Bytes Total size of an Ethernet Frame carrying an IP Packet with an empty TCP Segment – 24 + 20 + 20 = 64 bytes UDP: Size of … Read more

Sending and receiving UDP packets?

The receiver must set port of receiver to match port set in sender DatagramPacket. For debugging, try listening on port > 1024 (e.g. 5000 or 9000). Ports < 1024 are normally used by system services and need admin access to bind on such a port. If the receiver sends packet to the hard-coded port it’s … Read more

tech