erl 4.9.1. gen_udp, udp packages

Per Hedeland <>
Wed Apr 19 11:22:29 CEST 2000


 wrote:
>When you receive udp packages they look something like:
>{udp,{socket,<0.41.0>,#Port<0.12>,inet_udp},
>     {203,102,230,172},
>     1024,
>     [1,2,3,4,5,6,7]}
>
>I suppose the "1024" means something, I asumed its the port number but
>its not, its always 1024 and increasing with the number of open ports
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>so what does it represent?         ^^ Huh?:-)

The man page seems clear, and not obviously contradicting what you're
seeing:

              When UDP packets arrive at  the  opened  Port  they
              will  be  delivered  as  messages of the type {udp,
              Socket, IP, InPortNo, Packet}

              IP and  InPortNo  define  the  address  from  which
              Packet  came.

I.e. the number is the *source* port of the packet - delivering the
destination port with each packet isn't obviously useful.:-) If the
sender didn't bind to a specific port (in Erlang: Passed a Port value of
0 to gen_udp:open()), the kernel / IP stack will allocate one - the
algorithm for this varies, but on many/most Unices it will be the first
"free" port above 1023.

--Per Hedeland





More information about the erlang-questions mailing list