anchor.diff:  -author('Carlos Gonzalez <carlosj.gf@gmail.com>').
   
   -export([get_all/0, get_all/1, get_listening/3, get_connected/4]).
  --export([is_local/2, is_local_ip/1, main_ip/0, main_ip6/0]).
  +-export([is_local/2, is_local_ip/1, main_ip/0, main_ip6/0, start_ping/2]).
   -export([start_transport/5, start_connection/5, default_port/1]).
   -export([send/4, raw_send/2]).
   
  
positive.code:             send(AppId, Rest, MakeMsg, Opts)
      end;
  
  send(AppId, [{Proto, Ip, Port}|Rest]=All, MakeMsg, Opts) 
       when Proto==tcp; Proto==tls; Proto==sctp ->
      ?debug(AppId, "Transport send to ~p (~p)", [All, Proto]),
      case get_connected(AppId, Proto, Ip, Port) of
          [{Transport, Pid}|_] -> 
              SipMsg = MakeMsg(Transport),
              case do_send(Proto, Pid, SipMsg) of
                  ok -> {ok, SipMsg};
                  error -> send(AppId, Rest, MakeMsg, Opts)
              end;
          [] ->
              case start_connection(AppId, Proto, Ip, Port, Opts) of
                  {ok, Pid, Transport} ->
                      SipMsg = MakeMsg(Transport),
                      case do_send(Proto, Pid, SipMsg) of
                          ok -> {ok, SipMsg};
                          error -> send(AppId, Rest, MakeMsg, Opts)
                      end;
                  {error, Error} ->
                      ?notice(AppId, "error connecting to ~p:~p (~p): ~p",
  
negative.code:                        inet:ip_address(), inet:port_number(), nksip_lib:proplist()) ->
      {ok, pid(), nksip_transport:transport()} | {error, term()}.
  
  start_connection(AppId, udp, Ip, Port, Opts) ->
      nksip_transport_srv:start_connection(AppId, udp, Ip, Port, Opts);
  
  start_connection(AppId, Proto, Ip, Port, Opts) ->
      Max = nksip_config:get(max_connections),
      case nksip_counters:value(nksip_transport_tcp) of
  