Skip to content

Commit

Permalink
Add decoding of SCTP COOKIE ACK chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
ates committed Sep 11, 2013
1 parent 32f74de commit a1bc721
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
2 changes: 2 additions & 0 deletions include/pkt.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@
cookie
}).

-record(sctp_chunk_cookie_ack, {}).

-record(sctp_chunk_heartbeat, {
type = 1, info
}).
Expand Down
12 changes: 3 additions & 9 deletions src/pkt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -362,20 +362,12 @@ options(Offset, Payload) ->
sctp(<<SPort:16, DPort:16, VTag:32, Sum:32, Payload/binary>>) ->
SCTP = #sctp{
sport = SPort, dport = DPort, vtag = VTag,
sum = Sum, chunks = sctp_decode_chunks(Payload)
sum = Sum, chunks = sctp_decode_chunks(Payload, [])
},
{SCTP, []}.

-spec sctp_decode_chunks(binary()) -> [#sctp_chunk{}].
sctp_decode_chunks(Chunks) ->
sctp_decode_chunks(Chunks, []).

-spec sctp_decode_chunks(binary(), list()) -> [#sctp_chunk{}].
sctp_decode_chunks(<<>>, Acc) -> Acc;
sctp_decode_chunks(<<_Type:8, _Flags:8, Length:16, Rest/binary>>, Acc)
when Length =< 4 ->
sctp_decode_chunks(Rest, Acc);

sctp_decode_chunks(<<Type:8, Flags:8, Length:16, Rest/binary>>, Acc) ->
L = case Length rem 4 of
0 -> % No padding bytes
Expand Down Expand Up @@ -421,6 +413,8 @@ sctp_chunk_payload(?SCTP_CHUNK_INIT_ACK, <<Itag:32, Arwnd:32, OutStreams:16, InS
};
sctp_chunk_payload(?SCTP_CHUNK_COOKIE_ECHO, Cookie) ->
#sctp_chunk_cookie_echo{cookie = Cookie};
sctp_chunk_payload(?SCTP_CHUNK_COOKIE_ACK, <<>>) ->
#sctp_chunk_cookie_ack{};
sctp_chunk_payload(?SCTP_CHUNK_HEARTBEAT, <<Type:16, _Length:16, Info/binary>>) ->
#sctp_chunk_heartbeat{type = Type, info = Info};
sctp_chunk_payload(?SCTP_CHUNK_HEARTBEAT_ACK, <<Type:16, _Length:16, Info/binary>>) ->
Expand Down

0 comments on commit a1bc721

Please sign in to comment.