Skip to content

Instantly share code, notes, and snippets.

@Gustav-Simonsson
Created May 30, 2013 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gustav-Simonsson/5677494 to your computer and use it in GitHub Desktop.
Save Gustav-Simonsson/5677494 to your computer and use it in GitHub Desktop.
decode(Segment) ->
case Segment of
<< SourcePort:16, DestinationPort:16,
SequenceNumber:32,
AckNumber:32,
DataOffset:4, _Reserved:4, Flags:8, WindowSize:16,
Checksum:16, UrgentPointer:16,
Payload/binary>> when DataOffset>4
->
OptSize = (DataOffset - 5)*32,
<< Options:OptSize, Message/binary >> = Payload,
<> = <>,
%% Can now process the Message according to the
%% Options (if any) and the flags CWR, ..., FIN.
binary_to_list(Message)
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment