How to get first free udp port ?

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 ...


Go Back   Usenet Forums > Linux Forums > Linux Networking

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-11-2006
Jarek
 
Posts: n/a
Default How to get first free udp port ?

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.

Jarek
Reply With Quote
  #2 (permalink)  
Old 09-11-2006
David Schwartz
 
Posts: n/a
Default Re: How to get first free udp port ?


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

Reply With Quote
  #3 (permalink)  
Old 09-12-2006
Jarek
 
Posts: n/a
Default Re: How to get first free udp port ?

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
Reply With Quote
  #4 (permalink)  
Old 09-12-2006
Tauno Voipio
 
Posts: n/a
Default Re: How to get first free udp port ?

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

Reply With Quote
  #5 (permalink)  
Old 09-12-2006
David Schwartz
 
Posts: n/a
Default Re: How to get first free udp port ?


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

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:56 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0