This is a discussion on How to get first free udp port ? within the Linux Networking forums, part of the Linux Forums category; Hi all! Is there any syscall, to get first unused udp port on the linux machine ? Something like the port ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Jarek wrote: > Hi all! > > Is there any syscall, to get first unused udp port on the linux machine > ? Something like the port allocated by the system as TCP source port. It's not clear what you mean by "first unused". But you can bind to port zero (which asks the system to choose a port) for UDP just as you can for TCP. You can then call 'getsockname' to find out what port you are bound to. DS |
|
|||
|
Hello!
Użytkownik David Schwartz napisał: > > It's not clear what you mean by "first unused". But you can bind to > port zero (which asks the system to choose a port) for UDP just as you > can for TCP. You can then call 'getsockname' to find out what port you > are bound to. Thanks! I think, that this is what I was looking for. Do you know, if the port bind in this way will be from this range: /proc/sys/net/ipv4/ip_local_port_range ??? I want to avoid binding to low ports. best regards Jarek |
|
|||
|
Jarek wrote:
> Hello! > > Użytkownik David Schwartz napisał: > >> >> It's not clear what you mean by "first unused". But you can bind to >> port zero (which asks the system to choose a port) for UDP just as you >> can for TCP. You can then call 'getsockname' to find out what port you >> are bound to. > > > Thanks! I think, that this is what I was looking for. Do you know, if > the port bind in this way will be from this range: > > /proc/sys/net/ipv4/ip_local_port_range > > ??? I want to avoid binding to low ports. If you let the system choose, you won't get the low ports. -- Tauno Voipio tauno voipio (at) iki fi |
|
|||
|
Jarek wrote: > Thanks! I think, that this is what I was looking for. Do you know, if > the port bind in this way will be from this range: > > /proc/sys/net/ipv4/ip_local_port_range > > ??? I want to avoid binding to low ports. Yes, if you let the OS pick the port, it will pick a port from that range. You can also pick one yourself and pass it in a call to 'bind'. DS |
![]() |
| Thread Tools | |
| Display Modes | |
|
|