Subject: [Tsvwg] source port of 0 in TCP or UDP

From: Randall Stewart <[email-masked]>
Date: Tue, 16 Jan 2007 08:18:27 -0500

Hi all:

In looking at the IANA site you will find that
port 0 for TCP or UDP is "reserved".

Which implies that no application should be
using it...

But, what happens to an app that does?

Should a stack be capable of dealing with port 0... aka
allowing someone to bind it and then source/receive packet
to/from it?

This came up on a FreeBSD list.. and it makes me curious...

Thoughts would be appreciated :-)

R
-- 
Randall Stewart
803-345-0369 <or> 815-342-5222(cell)

---

From: Vlad Yasevich <[email-masked]>
Date: Tue, 16 Jan 2007 14:06:12 -0500

> allowing someone to bind it and then source/receive packet

Randall

All implementation I know treat port 0 as ephemeral and pick a
random port.  So how would one go about binding to it?  Is that a problem
that came up?

-vlad

---

From: Michael Tuexen <[email-masked]>
Date: Tue, 16 Jan 2007 21:25:32 +0100

Hi Vlad,

it is important to distinguish between the port number in the
sockaddr_in and sockaddr_in6 structures and the port numbers
being used in the transport protocol headers.

The IANA list is about the port numbers used in the transport
protocol headers.

In the API 0 has a special meaning when, for example, calling bind():
It tells the operating system to choose an ephemeral port.
This does not mean that 0 is considered ephemeral by the operating
system.

Best regards
Michael

---

From: Vlad Yasevich <[email-masked]>
Date: Tue, 16 Jan 2007 15:48:37 -0500

Michael

> This does not mean that 0 is considered ephemeral by the operating

Understood, but if there is no API to specify port 0 to the operating systems
then how would an application go about (ab)using it?

I don't see anything awful happening if port 0 is used.  In fact, I have
seen this happen inadvertently (was a bug that was fixed), but it didn't
result in any problems.

-vlad

---

From: Michael Tuexen <[email-masked]>
Date: Tue, 16 Jan 2007 22:11:59 +0100

> seen this happen inadvertently (was a bug that was fixed), but it  
Since you can not bind to port zero, how can you accept connections on
an end-point with port 0 or how can you send a packet from port 0?

---

From: Vlad Yasevich <[email-masked]>
Date: Tue, 16 Jan 2007 16:24:56 -0500

> an end-point with port 0 or how can you send a packet from port 0?

In that specific case, it was a bug in that port 0 ended up being actually
used to establish the connection.  As a result, everything worked, but packet
captures showed port 0.

-vlad

---

From: Ken Calvert <[email-masked]>
Date: Tue, 16 Jan 2007 16:26:20 -0500 (EST)

> This does not mean that 0 is considered ephemeral by the operating

Probably everybody here knows this, but...

I believe the value 0 was used in some well-known 
implementations as the "wildcard" value in socket data 
structures.  The packet-demux routine match a 0 in a 
socket's "remote port" field with any incoming port number.

If 0 became a legitimate port number, the demux algorithm
would need to be modified to distinguish between "wildcard" 
and the actual value "0".

KC
-- 
Ken Calvert, Associate Professor      Lab for Advanced Networking
[email-masked]                     University of Kentucky
Tel: +1.859.257.6745                 Hardymon Building, 2nd Floor
Fax: +1.859.323.1971                              301 Rose Street
http://www.cs.uky.edu/~calvert/          Lexington, KY 40506-0495

---

From: Rick Jones <[email-masked]>
Date: Tue, 16 Jan 2007 13:59:56 -0800

while existing/known api's provide no way to bind to port zero, i 
suspect one shouldn't ass-u-me that means one will never have an API or 
other mechanism which makes it possible?

rick jones
apologies if this missive from the peanut gallery has already been noted

---

From: "Brian F. G. Bidulock" <[email-masked]>
Date: Tue, 16 Jan 2007 15:10:08 -0700

Rick,

That's what I do: both the OpenSS7 sockets and STREAMS implementations
will accept a connection _from_ port 0, even though binding to port 0
will dynamically allocate a port number, and attempting to connect _to_
port 0 will yield EBADADDR or EADDRNOTAVAIL (depending on the interface).

--brian

Rick Jones wrote:                              (Tue, 16 Jan 2007 13:59:56)

-- 
Brian F. G. Bidulock
[email-masked]
http://www.openss7.org/