Skip to content

Instantly share code, notes, and snippets.

Avatar

deadc0de deadc0de6

View GitHub Profile
View scannerl-mysql-0.erl
-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").
View scannerl-mysql-4.erl
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
View scannerl-mysql-3.erl
-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};
View scannerl-mysql-2.erl
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 ->
View scannerl-mysql-1.erl
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)}.