Networking Forums

Networking Forums > Computer Networking > Linux Networking > How to get first free udp port ?

Reply
Thread Tools Display Modes

How to get first free udp port ?

 
 
Jarek
Guest
Posts: n/a

 
      09-11-2006, 02:52 PM
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
 
 
 
 
David Schwartz
Guest
Posts: n/a

 
      09-11-2006, 10:21 PM

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
 
Jarek
Guest
Posts: n/a

 
      09-12-2006, 12:59 PM
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
 
Tauno Voipio
Guest
Posts: n/a

 
      09-12-2006, 01:56 PM
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
 
David Schwartz
Guest
Posts: n/a

 
      09-12-2006, 03:44 PM

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Free SEO -Free dictionary list -Add a link to your website for free george Broadband 0 08-29-2008 04:57 PM
Free Ad-less anonymous web browsing (no limitation totally free)mychinesefriend.com/surf doper Wireless Internet 0 07-08-2008 02:26 AM
Linux free port allocation algorithm kreide@gmail.com Linux Networking 9 01-07-2008 07:19 PM
Win a Free gaming console, PS3, X-BOX or Nintendo wii, Free Prize Draw Michael Broadband 1 04-01-2007 05:43 PM
Free World Dialip offering free PSTN calling Linus Surguy Broadband 0 12-24-2003 06:57 AM



1 2 3 4 5 6 7 8 9 10 11