managing datagram sockets
Is there some way you can find out "free" ports which arn''t being used by tcp and/or udp? I know you can find free ports from 1024-5000 in tcp by setting sin_port to 0.
or am I just going to have to handle that manually?
any suggestions?
Are you trying to find an arbitrary local port on the client side? I''m not sure exactly what you are looking for. Maybe you can restate the question?
how can I find a udp port which isn''t being used locally? is that possible or do I just have to guess?
If you are trying to find an available port to run your server on, use netstat to find out which ports are in use. Then pick one that isn''t in use.
If you are trying to programmatically find a bind port for your client side, your docs for INADDR_ANY, and use port 0. The system will assign you an open port automatically.
If you are trying to programmatically find a bind port for your client side, your docs for INADDR_ANY, and use port 0. The system will assign you an open port automatically.
I think the poster wants to know how to find out within a program what sockets are being used for what purpose on a certain machine. Am I correct?
Under Windows:
To do this you can call getsockopt() with all the socket numbers from 0 to 65535. You see SOCKET which is the socket handle just has a 16 bit unsigned range. This is a nasty kludge way because you are calling the function with every single possible socket handle, but it will get you the information you want.
There may be security issues though as NT is quite good about hiding invalid handles from processes that didn''t allocate them.
Under Windows:
To do this you can call getsockopt() with all the socket numbers from 0 to 65535. You see SOCKET which is the socket handle just has a 16 bit unsigned range. This is a nasty kludge way because you are calling the function with every single possible socket handle, but it will get you the information you want.
There may be security issues though as NT is quite good about hiding invalid handles from processes that didn''t allocate them.
Martin Piper
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement