[erlang-questions] Packet size parsing

Christian S chsu79@REDACTED
Sat Feb 9 12:02:17 CET 2008

A slightly more generalized way to handle protocols with a header+payload is
to be able to tell the driver to collect B bytes before it sends a message.

The postgresql protocol has a header with
<<MessageType:8/integer, Length:32/big-endian-integer>>
then followed by (Length-4) bytes of payload.

So it would be nice to first tell it to send me a 5 byte header, not
more and not less,
then tell it to send me the payload size of data, still not more and not less.

I get uneasy about so much protocol stuff being done in C code. That
so easy to get
wrong and get wrong so it is exploitable. Just asking C to collect a
certain amount of
bytes before it sends the process a message is not much code to get wrong.

On Feb 8, 2008 5:59 PM, Tony Garnock-Jones <tonyg@REDACTED> wrote:
> Hi all,
> How difficult might it be to support, in the C inet runtime, a new kind
> of {packet, N} option for sockets,
>   {packet, N, Offset}
> where
>   N - number of bytes of big-endian length indicator
>   Offset - byte offset within the packet of the length indicator

More information about the erlang-questions mailing list