This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
callback_next_step(Args) when Args#args.moddata == undefined -> | |
{continue, Args#args.maxpkt, "", true}; | |
callback_next_step(Args) when Args#args.packetrcv < 1 -> | |
{result, {{error,up}, timeout}}; | |
callback_next_step(Args) -> | |
{result, parse_header(Args, Args#args.datarcv)}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parse_header(Args, | |
<< | |
Pldlen:24/little, % 3 bytes payload length | |
_:8, % 1 byte sequence id or packet nb | |
Pld/binary % content | |
>>) -> | |
case byte_size(Pld) == Pldlen of | |
true -> | |
parse_content(Args, Pld); | |
false -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-define(PROTO, 16#0a). % only interested in protocol version 10 | |
parse_content(_Args, | |
<< | |
?PROTO:8, % protocol version | |
Rest/binary | |
>>) -> | |
case find_null(Rest, 1) of | |
error -> | |
{{error, up}, unexpected_data}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find_null(Bin, Pos) -> | |
case Bin of | |
<<Start:Pos/binary, 0, Rest/binary>> -> | |
% found | |
{Start, Rest}; | |
<<Bin:Pos/binary>> -> | |
% not found | |
error; | |
<<_:Pos/binary, _/binary>>=B -> | |
% go forward |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(fp_mysql_greeting). | |
-define(TIMEOUT, 3000). % milli-seconds | |
-define(PORT, 3306). % mysql port | |
-define(MAXPKT, 1). % only greeting packet is needed | |
-define(DESCRIPTION, "TCP/3306: Mysql version identification"). |