anchor.diff:              send(AppId, Rest, MakeMsg, Opts)
       end;
   
  +send(AppId, [{Proto, Ip, 0}|Rest], MakeMsg, Opts)
  +    when Proto==udp; Proto==tcp; Proto==tls; Proto==sctp ->
  +    send(AppId, [{Proto, Ip, default_port(Proto)}|Rest], MakeMsg, Opts);
  +
  +% send(AppId, [{udp, Ip, Port}|Rest]=All, MakeMsg, Opts) -> 
  +%     ?debug(AppId, "Transport send to ~p (udp)", [All]),
  +%     Class = case size(Ip) of 4 -> ipv4; 8 -> ipv6 end,
  +%     case get_listening(AppId, udp, Class) of
  +%         [{Transport1, Pid}|_] -> 
  +%             Transport2 = Transport1#transport{remote_ip=Ip, remote_port=Port},
  +%             SipMsg = MakeMsg(Transport2),
  +%             case nksip_transport_udp:send(Pid, SipMsg) of
  +%                 ok -> 
  +%                     {ok, SipMsg};
  +%                 error -> 
  +%                     send(AppId, [{tcp, Ip, Port}|Rest], MakeMsg, Opts)
  +%             end;
  +%         [] ->
  +%             send(AppId, [{tcp, Ip, Port}|Rest], MakeMsg, Opts)
  +%     end;
  +
   send(AppId, [{Proto, Ip, Port}|Rest]=All, MakeMsg, Opts) 
  -     when Proto==tcp; Proto==tls; Proto==sctp ->
  +    when Proto==udp; 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)
  +                ok -> 
  +                    {ok, SipMsg};
  +                error when Proto==udp ->
  +                    send(AppId, [{tcp, Ip, Port}|Rest], MakeMsg, Opts);
  +                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)
  +                        ok -> 
  +                            {ok, SipMsg};
  +                        error when Proto==udp ->
  +                            send(AppId, [{tcp, Ip, Port}|Rest], MakeMsg, Opts);
  +                        error -> 
  +                            send(AppId, Rest, MakeMsg, Opts)
                       end;
                   {error, Error} ->
                       ?notice(AppId, "error connecting to ~p:~p (~p): ~p",
  
positive.code:     ?debug(AppId, "Transport send to ~p (~p)", [All, Resolv]),
      send(AppId, Resolv++Rest, MakeMsg, Opts);
  
  send(AppId, [{udp, Ip, 0}|Rest], MakeMsg, Opts) ->
      %% If no port was explicitly specified, use default.
      send(AppId, [{udp, Ip, 5060}|Rest], MakeMsg, Opts);
  
  send(AppId, [{udp, Ip, Port}|Rest]=All, MakeMsg, Opts) -> 
      ?debug(AppId, "Transport send to ~p (udp)", [All]),
      Class = case size(Ip) of 4 -> ipv4; 8 -> ipv6 end,
      case get_listening(AppId, udp, Class) of
          [{Transport1, Pid}|_] -> 
              Transport2 = Transport1#transport{remote_ip=Ip, remote_port=Port},
              SipMsg = MakeMsg(Transport2),
              case nksip_transport_udp:send(Pid, SipMsg) of
                  ok -> 
                      {ok, SipMsg};
                  error -> 
                      send(AppId, [{tcp, Ip, Port}|Rest], MakeMsg, Opts)
              end;
          [] ->
              send(AppId, [{tcp, Ip, Port}|Rest], MakeMsg, Opts)
      end;
  
  send(AppId, [{current, {udp, Ip, Port}}|Rest], MakeMsg, Opts) ->
      send(AppId, [{udp, Ip,Port}|Rest], MakeMsg, Opts);
  
  send(AppId, [{current, {Proto, Ip, Port}}|Rest]=All, MakeMsg, Opts) 
          when Proto==tcp; Proto==tls; Proto==sctp ->
  
negative.code:     nksip_config:get(local_ips).
  
  
  %% @doc
  -spec start_ping(nksip:app_id(), nksip:transport()) ->
      ok | {error, not_found}.
  
  start_ping(AppId, #transport{proto=Proto, remote_ip=Ip, remote_port=Port}) ->
      case get_connected(AppId, Proto, Ip, Port) of
          [{_, Pid}|_] -> do_start_ping(Proto, Pid, Ip, Port);
          [] -> {error, not_found}
      end.
  
  
  %% @doc Start a new listening transport.
  -spec start_transport(nksip:app_id(), nksip:protocol(), inet:ip_address(), 
                        inet:port_number(), nksip_lib:proplist()) ->
  