Reputation: 1317
I'm trying to read from a large range of UDP ports (10k) but I want to do so without creating 10k sockets and listen to them (and use epoll
). One solution for this is to use iptables and write rules to forward packets to a single port that the server is listening on. However, I must be able to read the original destination port in the code.
Does anybody know if it's even possible to do this?
Upvotes: 0
Views: 205
Reputation: 788
You could probably do this using the network tunneling interface (tun). If you use iptables to forward to your tun device, then your program could read packets from there. (You'd need to interpret the IP headers yourself, though, perhaps using a library like libtins.)
There's a decent tutorial here: http://backreference.org/2010/03/26/tuntap-interface-tutorial/
Upvotes: 1
Reputation: 232
'recvfrom' can get the remote sockaddr and then using inet_ntop and ntohs to get ip and port.
Upvotes: 0