Skip to content

Commit

Permalink
Move match empty binary to the end
Browse files Browse the repository at this point in the history
  • Loading branch information
ates committed Aug 27, 2015
1 parent 808eafa commit f21be77
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/pkt_sctp.erl
Expand Up @@ -45,7 +45,6 @@ codec(<<SPort:16, DPort:16, VTag:32, Sum:32, Payload/binary>>) ->

%% Internal functions

decode_chunks(<<>>, Acc) -> {Acc, <<>>};
decode_chunks(<<Type:8, Flags:8, Length:16, Rest/binary>>, Acc) when Length /= 0 ->
{L, Pad} = case Length rem 4 of
0 -> % No padding bytes
Expand All @@ -55,6 +54,7 @@ decode_chunks(<<Type:8, Flags:8, Length:16, Rest/binary>>, Acc) when Length /= 0
end,
<<Payload:L/binary-unit:8, _:Pad, Tail/binary>> = Rest,
decode_chunks(Tail, [chunk(Type, Flags, Length, Payload) | Acc]);
decode_chunks(<<>>, Acc) -> {Acc, <<>>};
%% Ignore other bytes which are not SCTP chunks (VSS, ...)
decode_chunks(Other, Acc) -> {Acc, Other}.

Expand Down Expand Up @@ -116,8 +116,6 @@ chunk_payload(?SCTP_CHUNK_ABORT, Errors) ->
chunk_payload(_, Data) ->
Data.

init_params(<<>>, Acc) -> Acc;

%% IPv4 Address Parameter
init_params(<<5:16, 8:16, A:8, B:8, C:8, D:8, Rest/binary>>, Acc) ->
init_params(Rest, [{ipv4, {A, B, C, D}} | Acc]);
Expand Down Expand Up @@ -153,15 +151,15 @@ init_params(<<12:16, Length:16, Rest/binary>>, Acc) ->
L = Length - 4,
<<Types:L/binary-unit:8, Tail/binary>> = Rest,
init_params(Tail, [{address_types, [AddressType(V) || <<V:16>> <= Types]} | Acc]);
init_params(<<>>, Acc) -> Acc;
%% Ignore ECN and Forward TSN parameters
init_params(_, Acc) -> Acc.

error_causes(<<>>, Acc) ->
Acc;
error_causes(<<Code:16, Length:16, Rest/binary>>, Acc) ->
L = Length - 4,
<<Opts:L/binary-unit:8, Tail/binary>> = Rest,
error_causes(Tail, [sctp_error(Code, L, Opts) | Acc]).
error_causes(Tail, [sctp_error(Code, L, Opts) | Acc]);
error_causes(<<>>, Acc) -> Acc.

sctp_error(1, _Length, <<Ident:16, _Reserved:8>>) ->
#sctp_error_cause{
Expand Down

0 comments on commit f21be77

Please sign in to comment.