\section{Application Programming Interface}

% -----------------------------------------------------------------
\begin{slide}{}

   It is important to separate the {\it implementation} of protocols
   from the {\it interface} they export. This is espeically important
   at the transport layer since this defines the point where application
   programs typically access the network. This interface is often called
   the {\it application programming interface}, or API.

   \pichere{api_layers.eps,height=3in}

   Notes
   \begin{sitem}
      \item The API is usually defined by the OS.
      \item We now focus on one specific API: {\it sockets}
      \item Defined by BSD Unix, but ported to other systems
   \end{sitem}
\end{slide}
% -----------------------------------------------------------------
\begin{slide}{}

   \subsection{Socket Operations}

   \begin{sitem}
      \item Creating a socket
\begin{verbatim}
int socket(int domain, int type, int protocol)
\end{verbatim}
      \begin{sitem}
         \item {\tt domain=PF\_INET, PF\_UNIX}
         \item {\tt type=SOCK\_STREAM, SOCK\_DGRAM}
      \end{sitem}

      \item Passive open on server
\begin{verbatim}
int bind(int socket, struct sockaddr *address, 
         int addr_len)
int listen(int socket, int backlog)
int accept(int socket, struct sockaddr *address, 
           int *addr_len)
\end{verbatim}

      \item Active open on client
\begin{verbatim}
int connect(int socket, struct sockaddr *address, 
            int addr_len)
   \end{verbatim}

      \item Sending and receiving messages
\begin{verbatim}
int write(int socket, char *message, int msg_len, 
          int flags)
int read(int socket, char *buffer, int buf_len, 
         int flags)
\end{verbatim}
   \end{sitem}
\end{slide}

