anchor.diff:  %% Internal application API
   %%====================================================================
   
  +-define(DefaultTransport,  {tcp, gen_tcp, tcp_closed} ).
  +
   %%--------------------------------------------------------------------
   -spec start_connection(role(),
   		       inet:socket(),
  
positive.code:     D.
  
  %%%----------------------------------------------------------------
  socket_control(Socket, Pid, Transport) ->
      case Transport:controlling_process(Socket, Pid) of
  	ok ->
  	    gen_statem:cast(Pid, socket_control);
  	{error, Reason}	->
  
negative.code:     Ssh#ssh{c_vsn = NumVsn , c_version = StrVsn};
  counterpart_versions(NumVsn, StrVsn, #ssh{role = client} = Ssh) ->
      Ssh#ssh{s_vsn = NumVsn , s_version = StrVsn}.
  
  ssh_info([], _State, Acc) ->
      Acc;
  ssh_info([client_version | Rest], #data{ssh_params = #ssh{c_vsn = IntVsn,
  							   c_version = StringVsn}} = State, Acc) ->
      ssh_info(Rest, State, [{client_version, {IntVsn, StringVsn}} | Acc]);
  
  ssh_info([server_version | Rest], #data{ssh_params =#ssh{s_vsn = IntVsn,
  							  s_version = StringVsn}} = State, Acc) ->
      ssh_info(Rest, State, [{server_version, {IntVsn, StringVsn}} | Acc]);
  ssh_info([peer | Rest], #data{ssh_params = #ssh{peer = Peer}} = State, Acc) ->
      ssh_info(Rest, State, [{peer, Peer} | Acc]);
  ssh_info([sockname | Rest], #data{socket = Socket} = State, Acc) ->
      {ok, SockName} = inet:sockname(Socket),
     ssh_info(Rest, State, [{sockname, SockName}|Acc]);
  ssh_info([user | Rest], #data{auth_user = User} = State, Acc) ->
      ssh_info(Rest, State, [{user, User}|Acc]);
  ssh_info([ _ | Rest], State, Acc) ->
      ssh_info(Rest, State, Acc).
  
  
  ssh_channel_info([], _, Acc) ->
      Acc;
  
  ssh_channel_info([recv_window | Rest], #channel{recv_window_size = WinSize,
  						   recv_packet_size = Packsize
  						  } = Channel, Acc) ->
      ssh_channel_info(Rest, Channel, [{recv_window, {{win_size, WinSize},
  						      {packet_size, Packsize}}} | Acc]);
  ssh_channel_info([send_window | Rest], #channel{send_window_size = WinSize,
  						send_packet_size = Packsize
  					       } = Channel, Acc) ->
      ssh_channel_info(Rest, Channel, [{send_window, {{win_size, WinSize},
  						      {packet_size, Packsize}}} | Acc]);
  ssh_channel_info([ _ | Rest], Channel, Acc) ->
      ssh_channel_info(Rest, Channel, Acc).
  
  
  log_error(Reason) ->
      Report = io_lib:format("Erlang ssh connection handler failed with reason:~n"
  			   "    ~p~n"
  			   "Stacktrace:~n"
  			   "    ~p~n",
  			   [Reason, erlang:get_stacktrace()]),
      error_logger:error_report(Report).
  
  
  %%%----------------------------------------------------------------
  not_connected_filter({connection_reply, _Data}) -> true;
  not_connected_filter(_) -> false.
  
  %%%----------------------------------------------------------------
  send_replies(Repls, State) ->
      lists:foldl(fun get_repl/2,
  		{[],State},
  		Repls).
  
  get_repl({connection_reply,Msg}, {CallRepls,S}) ->
      {CallRepls, send_msg(Msg,S)};
  get_repl({channel_data,undefined,_Data}, Acc) ->
      Acc;
  get_repl({channel_data,Pid,Data}, Acc) ->
      Pid ! {ssh_cm, self(), Data},
      Acc;
  get_repl({channel_request_reply,From,Data}, {CallRepls,S}) ->
      {[{reply,From,Data}|CallRepls], S};
  get_repl({flow_control,Cache,Channel,From,Msg}, {CallRepls,S}) ->
      ssh_channel:cache_update(Cache, Channel#channel{flow_control = undefined}),
      {[{reply,From,Msg}|CallRepls], S};
  get_repl({flow_control,From,Msg}, {CallRepls,S}) ->
      {[{reply,From,Msg}|CallRepls], S};
  get_repl(noreply, Acc) ->
      Acc;
  get_repl(X, Acc) ->
      exit({get_repl,X,Acc}).
  
  %%%----------------------------------------------------------------
  disconnect_fun({disconnect,Msg}, D) ->
      disconnect_fun(Msg, D);
  disconnect_fun(Reason,  #data{opts=Opts}) ->
      case proplists:get_value(disconnectfun, Opts) of
  	undefined ->
  	    ok;
  	Fun ->
  	    catch Fun(Reason)
       end.
  
  unexpected_fun(UnexpectedMessage, #data{opts = Opts,
  					ssh_params = #ssh{peer = {_,Peer} }
  				       } ) ->
      case proplists:get_value(unexpectedfun, Opts) of
  	undefined ->
  	    report;
  	Fun ->
  	    catch Fun(UnexpectedMessage, Peer)
      end.
  
  
  debug_fun(#ssh_msg_debug{always_display = Display,
  			 message = DbgMsg,
  			 language = Lang},
  	  #data{opts = Opts}) ->
      case proplists:get_value(ssh_msg_debug_fun, Opts) of
  	undefined ->
  	    ok;
  	Fun ->
  	    catch Fun(self(), Display, DbgMsg, Lang)
      end.
  
  
  connected_fun(User, Method, #data{ssh_params = #ssh{peer = {_,Peer}},
  				  opts = Opts}) ->
  