\section{Using SRV DNS Records}
\label{sec:srv}

The following procedure is experimental and relies on DNS SRV records
(RFC 2052 \cite{rfc2052}). The steps listed below are used in place of
the two steps in section \ref{sec:server}. 

If a step elicits no addresses, the client continues to the next step.
However if a step elicits one or more addresses, but no SIP server at
any of those addresses responds, then the client concludes the server
is down and doesn't continue on to the next step.

When SRV records are to be used, the protocol to use when querying for
the SRV record is ``sip''.  SRV records contain port numbers for
servers, in addition to IP addresses; the client always uses this port
number when contacting the SIP server.  Otherwise, the port number in
the SIP URI is used, if present.  If there is no port number in the URI,
the default port, 5060, is used.

\begin{enumerate}
\item If the \header{host} portion of the \header{Request-URI} is an IP
address, the client contacts the server at the given address. If the
\header{host} portion of the \header{Request-URI} is not an IP address,
the client proceeds to the next step.

\item The \header{Request-URI} is examined. If it contains an explicit
port number, the next two steps are skipped. 

\item The \header{Request-URI} is examined.  If it does not specify a
protocol (TCP or UDP), the client queries the name server for SRV
records for both UDP (if supported by the client) and TCP (if supported
by the client) SIP servers.  The format of these queries is defined in
RFC 2052 \cite{rfc2052}.  The results of the query or queries are merged
together and ordered based on priority.  Then, the searching technique
outlined in RFC 2052 \cite{rfc2052} is used to select servers in order. 
If DNS doesn't return any records, the user goes to the last step. 
Otherwise, the user attempts to contact each server in the order listed. 
If no server is contacted, the user gives up. 

\item If the \header{Request-URI} specifies a protocol (TCP or UDP) that
is supported by the client, the client queries the name server for SRV
records for SIP servers of that protocol type only.  If the client does
not support the protocol specified in the \header{Request-URI}, it gives
up.  The searching technique outlined in RFC 2052 \cite{rfc2052} is used
to select servers from the DNS response in order.  If DNS doesn't return
any records, the user goes to the last step.  Otherwise, the user
attempts to contact each server in the order listed.  If no server is
contacted, the user gives up.

\item The client queries the name server for address records for the
host portion of the \header{Request-URI}.  If there were no address
records, the client stops, as it has been unable to locate a server.  By
address record, we mean A RR's, AAAA RR's, or their most modern
equivalent.

\end{enumerate}

A client {\MAY} cache a successful DNS query result.  A successful query
is one which contained records in the answer, and a server was contacted
at one of the addresses from the answer.  When the client wishes to send
a request to the same host, it starts the search as if it had just
received this answer from the name server.  The server uses the
procedures specified in RFC1035 \cite{rfc1035} regarding cache
invalidation when the time-to-live of the DNS result expires.  If the
client does not find a SIP server among the addresses listed in the
cached answer, it starts the search at the beginning of the sequence
described above.

For example, consider a client that wishes to send a SIP request.  The
\header{Request-URI} for the destination is {\tt sip:user@company.com.}
The client only supports UDP.  It would follow these steps:

\begin{enumerate}

\item The host portion is not an IP address, so the client goes to
step 2 above.

\item The client does a DNS query of QNAME=''sip.udp.company.com'',
QCLASS=IN, QTYPE=SRV.  Since it doesn't support TCP, it omits the TCP
query.  There were no addresses in the DNS response, so the client goes
to the next step.

\item The client does a DNS query for A records for
``company.com''. An address is found, so that client attempts to
contact a server at that address at port 5060.
\end{enumerate}
