UDP+binary+passive and prim_inet:recvfrom/3 bug?

Samuel Tardieu sam@REDACTED
Fri Jan 5 20:42:05 CET 2001


On  5/01, Tony Rogvall wrote:

| From inet_drv.c
| 
| /*
| ** passive mode reply:
| **        {inet_async, S, Ref, {ok,[H1,...Hsz | Data]}}
| */
| 
| This means that the inet_drv ADDs a header list of sz bytes. In this case
| the header data is the Familiy, Port and Address, the rest my or may  not be a
| binary.

However, the following code:

-module (bug).
-export ([start_udp/0]).

start_udp () ->
  {ok, U} = gen_udp:open (4161, [binary, {active, false}]),
  io:format ("Received: ~p~n", [prim_inet:recvfrom (U, 1500)]),
  erlang:halt ().

gives, when a UDP packet is received on port 4161:

{ok,<<1,12,73,127,0,0,1,0,6,1,0,0,1,0,0,0,0,0,0,6,102,111,111,98,97,114,0,0,1,0,1>>}

If the binary option is removed, it gives:

{ok,{{127,0,0,1},
     3154,
     [0,6,1,0,0,1,0,0,0,0,0,0,6,102,111,111,98,97,114,0,0,1,0,1]}}





More information about the erlang-questions mailing list