how to bind a server to different ports instead of a sing le one?
i am writing a tcp server code to monitor tcp/ip traffic coming to my system. Can anyone have the开发者_运维百科 idea about how to bind to different tcp ports,instead of a single port. or can anyone ve the idea about how to do it?
expecting ideas from alll good hearts
Take a look at libpcap, it's closer to what it sounds like you need.
For each port you are listening on you need to prepare the data structures required to bind to that port and listen on it. You cannot listen on ALL ports -- unless you work at driver level and intercept the packets before they are dispatched to the application listening on a port. So effectively, if you will, inside your app, you will start multiple servers -- one for each port -- but once you have acquired a client connection you can share the same code for all requests coming on all ports (you are listening to).
You'd need to create one socket per port you want to bind. But how this will help you to "monitor tcp/ip traffic coming to your system" I am not sure. Probably it won't.
精彩评论