SFC UDP Port Multiplexing

How to create a client UDP socket in C ++ so that it can listen on the port that is being listened to by another application? In other words, how can I apply port multiplexing in C ++?

+5
source share
3 answers

I want to listen to only one port

You can do this with a sniffer. Just ignore packets from different ports.

I may need to stop it from sending some specific packages, because my program will send it instead of the original application

Well, here I suggest you give up sniffers and use the MITM technique .

PREROUTING, "". , UDP, Linux, iptables "" , "":

1. ( , ):

iptables -t nat -A PREROUTING -i <iface> -p <proto> --dport <dport>
    -j REDIRECT --to-port <newport>

2. <newport>.

3. ( ). "" , getsockopt SO_ORIGINAL_DST, .

, ... , , :-) , .

+3

, tcpdump snoop, . , libpcap, .

SO_REUSEADDR SO_REUSEPORT, . : , .

+2

- - , select(2) poll(2).

, , . .

, IP ( a.k.a.) . ethernet. , , , .

, .

+1

All Articles