Unicast UDP: two listening processes on the same udp port; only one packet reception

Purpose: To receive unicast UDP packets sent on the same port in two different processes.

System: Linux, language: C

I can bind two sockets in two different processes to the same port using SO_REUSEADDR. But as expected, packets are accepted in only one (one binding later).

Can you receive packages in both processes? If not, how is tcpdump able to read but not consume packets.

+3


source to share


3 answers


Why Unicast? This is exactly what multicast is for.



To answer the second question, it tcpdump

gets a copy of every packet that it listens to with bpf

, and this is for explicit support by the network card driver.

0


source


This is not possible with the sockets API, and tcpdump fetches packets directly from the network interface, before any TCP / IP processing.



Your only chance is to receive packages in one process and send them to another.

0


source


If you open a socket, bind, listen, and then fork () your process, requests for incoming connections will be forwarded each time to an arbitrarily chosen one of these processes (I never bothered to figure out the strategy that Linux uses because it balances the load well ).

I am currently testing the same behavior with a UDP server.

0


source







All Articles