Application layers
Domain Name System (DNS)
    Domain Name System (DNS) is a hostname for IP address translation service. DNS
    is a distributed database implemented in a hierarchy of name servers. It is an
    application layer protocol for message exchange between clients and servers. It is
    required for the functioning of the Internet.
    Purpose
     DNS is a host name to IP Address translation service.
     It converts the names we type in our web browser address bar to the IP
      Address of web servers hosting those sites.
    DNS Resolution-
       DNS Resolution is a process of resolving a domain name onto an IP Address.
Requirement
Every host is identified by the IP address but remembering numbers is very difficult
for people also the IP addresses are not static therefore a mapping is required to
change the domain name to the IP address. So, DNS is used to convert the domain
name of the websites to their numerical IP address.
There are various kinds of DOMAIN:
Generic Domains
   o   It defines the registered hosts according to their generic behavior.
   o   Each node in a tree defines the domain name, which is an index to the DNS
       database.
   o   It uses three-character labels, and these labels describe the organization type.
              2. Country Domain - It categorizes according to the country. For
                 example - (.in - India), (.uk - United Kingdom).
    Inverse Domains
   Inverse domain is used to map an address to a name.
   For example, a client send a request to the server for performing a particular task,
    server finds a list of authorized client. The list contains only IP addresses of the
    client.
   The server sends a query to the DNS server to map an address to a name to
    determine if the client is on the authorized list.
   This query is called an inverse query.
   This query is handled by first level node called arpa.
    Working of DNS
       o   DNS is a client/server network communication protocol. DNS clients send
           requests to the. server while DNS servers send responses to the client.
   o   Client requests contain a name which is converted into an IP address known
       as a forward DNS lookups while requests containing an IP address which is
       converted into a name known as reverse DNS lookups.
   o   DNS implements a distributed database to store the name of all the hosts
       available on the internet.
   o   If a client like a web browser sends a request containing a hostname, then a
       piece of software such as DNS resolver sends a request to the DNS server to
       obtain the IP address of a hostname. If DNS server does not contain the IP
       address associated with a hostname, then it forwards the request to another
       DNS server. If IP address has arrived at the resolver, which in turn completes
       the request over the internet protocol.
                        SMTP (Simple Mail Transfer Protocol)
SMTP mainly stands for Simple Mail Transfer Protocol. Basically, the actual
transfer of mail is done through the message transfer agents(MTA). Thus in order
to send the mail, the system must have the client MTA and in order to receive the
mail, the system must have a server MTA.
      In order to define the MTA client and server on the Internet, there is a
       formal way and it is known as Simple Mail Transfer Protocol(SMTP).
      SMTP also makes the use of TCP/IP for sending and receiving e-mail.
      SMTP is based on the client/server model.
      The original standard port for SMTP is Port 25.
      Using this protocol, the client who wants to send the e-mail first opens a
       TCP connection to the SMTP server and then sends the e-mail across the
       TCP connection. It is important to note that the SMTP server is always in
       listening mode. As soon as it listens for the TCP connection from any client
       then the connection is Initiated on port 25 and after the successful
       connection, the client sends the e-mail/message immediately.
SMTP is used two times while sending an Email:
   1. Between the Sender and Sender's mail server
   2. Between the Sender’s mail server and the Receiver’s mail server
It is important to note that in order to receive or download the email,
      There is a need for another protocol between the mail server of receiver and
       the receiver.
      Commonly used protocols are POP3 and IMAP. Thus these two are mail
       access agents.
Architecture of SMTP
All the users make use of User Agent (UA). The Mail Transfer
Agent (MTA) mainly helps to exchange all the messages in between both sender
and receiver using the TCP/IP. The system administrator has the authority to
configure the set up of local MTA, thus the users who are sending the email do not
need to deal with the MTA.
The MTA keeps the queue in the pool of messages, if the receiver is not available
at that moment then MTA can schedule the repeat delivery of all the messages.
MTA (Mail User Agent) forwards the emails into mailboxes of the user's local
system, and then the user agent (UA) can download those messages at any time.
The SMTP Client as well as the SMTP server both has two main components and
these are:
      UA(User-Agent)
      MTA(Mail Transfer Agent)
Let us now take a look at communication between the sender and the receiver:
The user agent at the sender side prepares the message and then sent it to the MTA.
The task of the MTA is to transfer the Email across the network to the Receiver
MTA. Also in order to send the Email, a system must have the client MTA and in
order to receive the email, a system must have a server MTA.
SMTP Protocol Method
   1. Store-and-Forward Method
       The store and forward method is used within an organization.
   2. End-to-End Method
       Mainly the end-to-end method is used to communicate between the different
       organizations
An SMTP client is the one who wants to send the mail and will definitely contact
the destination’s host SMTP directly in the order to send the Email to the
destination. Also, the session is initiated by the client SMPT.
On the other hand, the SMTP server will keep the mail to itself until it is
successfully copied to the SMTP at the receiver. The server SMTP mainly
responds to the session request.
Thus the session is started by the client-SMTP and the server-SMTP will respond
to the request of the sender.
Characteristics of SMTP
Let us take a look at the characteristics of the SMTP:
      SMTP makes use of Port 25.
      It makes use of persistent TCP connections and thus can send multiple
       emails all at once.
      It is a stateless protocol.
      It is a connection-oriented protocol.
      It makes use of TCP at the transport layer.
      It is a push control protocol.
Advantages of SMTP
Let us take a look at the advantages offered by the simple mail transfer
protocol(SMTP):
      SMTP offers reliability in terms of the outgoing email messages.
      It is the simplest form of communication between various computers in a
       network via Email.
      In those cases where a particular message was not delivered
       successfully then, the SMTP server always tries to re-send the same
       message until the transmission becomes successful.
Disadvantages of SMTP
      SMTP does not provide good security.
      It is only limited to 7-bit ASCII characters.
      Beyond some specific length, email messages are rejected by SMTP servers.
      The usefulness of SMTP is limited by its simplicity.
          With the help of SMTP, the transmission of executable files and binary files
           is not possible until they get converted into text files.
                                         POP Protocol
    POP is a short form of Post Office Protocol. It is another protocol present at the
    Application Layer of the OSI reference model.
          POP is mainly a message access protocol.
          POP is basically an internet standard protocol and as we already told you it
           works on the application layer and is used by the local email software in
           order to retrieve emails from the remote email server over the TCP/IP
           connection.
          The Post office Protocol (POP) does not allow any search facility.
          This protocol mainly allows one protocol to be created on the server.
          As this protocol supports offline access to the messages and so less internet
           usage time is required by this.
          Non-email data is not accessed by this protocol.
          Some of the common clients that make use of POP3 are Gmail, Netscape,
           Internet Explorer, Eudora.
    Purpose-
     It is a message access protocol.
     It enables the clients to receive or download the emails from their remote mail
      server.
     POP version 3 (POP3) is the most popularly used version.
    Working of POP
    All the incoming messages are stored on the POP server until the user login by
    using an email client and downloads the message to their computer. After the
    message is downloaded by the user it gets deleted from the server.
As we know that the SMTP is used to transfer the email message from the server to
the server, basically POP is used to collect the email with an email client from the
server and it does not include means to send messages.
If any user tries to check all the recent emails then they will establish a connection
with the POP3 at the server-side. The user sends the username and password to the
server machine for getting the proper authentication. After getting the connection,
users can receive all text-based emails and store them on their local terminal
(machine), then finally discard all server copies and then breaks the connection
from the server machine.
In order to retrieve a message from the server following steps are taken;
      Firstly a TCP connection is established by the client using port 110.
      The client identifies itself to the server.
      After that client issues a series of POP3 commands.
Features of POP protocol
Given below are some of the features provided by the POP protocol:
      The POP protocol uses PORT 110.
      It makes the use of a Persistent TCP connection.
      It is a Pull protocol.
      It is a connection-oriented protocol.
      The POP protocol is a stateful protocol until the mail is downloaded and
       across the sessions, it is a stateless protocol.
 Commands                                     Description
  LOGIN           This command is used to open a connection
                  This command is used to display the messages that are
      STAT
                  currently in the mailbox.
      DELE        This command is used to delete a message.
                  This command is mainly used to reset the session to its initial
      RSET
                  state.
      QUIT        This command is used to log off the session.
                  This command is mainly used to get the summary of each
      LIST
                  message where each message summary is shown.
                  This command is mainly used to select a mailbox in order to
   RETR
                  access the messages.
Advantages of POP
      This protocol does not require any internet connection in order to access the
       downloaded emails.
      In order to receive emails on a single device, POP3 is very useful.
      The Configuration of this protocol is simple and it is easy to use.
      Less storage space is needed in order to store emails on the hard disk.
      This protocol is much better for the ones who hardly check their email on
       any other computer.
Disadvantages of POP
      The same email account cannot be accessed from multiple computers or
       devices.
      The spread of the virus is easily using this protocol because it is possible that
       the file attached with the email contains the virus.
      The transfer of the local email folder to another email client terminal point is
       a difficult task.
                            File Transfer Protocol (FTP)
   o   FTP stands for File transfer protocol.
   o   FTP is a standard internet protocol provided by TCP/IP used for transmitting
       the files from one host to another.
   o   It is mainly used for transferring the web page files from their creator to the
       computer that acts as a server for other computers on the internet.
   o   It is also used for downloading the files to computer from other servers.
Objectives of FTP
   o   It provides the sharing of files.
   o   It is used to encourage the use of remote computers.
   o   It transfers the data more reliably and efficiently.
Why FTP?
Although transferring files from one system to another is very simple and
straightforward, but sometimes it can cause problems. For example, two systems
may have different file conventions. Two systems may have different ways to
represent text and data. Two systems may have different directory structures. FTP
protocol overcomes these problems by establishing two connections between hosts.
One connection is used for data transfer, and another connection is used for the
control connection.
Mechanism of FTP
The above figure shows the basic model of the FTP. The FTP client has three
components: the user interface, control process, and data transfer process. The server
has two components: the server control process and the server data transfer process.
There are two types of connections in FTP:
   o   Control Connection: The control connection uses very simple rules for
       communication. Through control connection, we can transfer a line of
       command or line of response at a time. The control connection is made
       between the control processes. The control connection remains connected
       during the entire interactive FTP session.
   o   Data Connection: The Data Connection uses very complex rules as data
       types may vary. The data connection is made between data transfer processes.
       The data connection opens when a command comes for transferring the files
       and closes when the file is transferred.
FTP Clients
   o   FTP client is a program that implements a file transfer protocol which allows
       you to transfer files between two hosts on the internet.
   o   It allows a user to connect to a remote host and upload or download the files.
  o   It has a set of commands that we can use to connect to a host, transfer the files
      between you and your host and close the connection.
  o   The FTP program is also available as a built-in component in a Web browser.
      This GUI based FTP client makes the file transfer very easy and also does not
      require to remember the FTP commands.
Advantages of FTP:
  o   Speed: One of the biggest advantages of FTP is speed. The FTP is one of the
      fastest way to transfer the files from one computer to another computer.
  o   Efficient: It is more efficient as we do not need to complete all the operations
      to get the entire file.
  o   Security: To access the FTP server, we need to login with the username and
      password. Therefore, we can say that FTP is more secure.
  o   Back & forth movement: FTP allows us to transfer the files back and forth.
      Suppose you are a manager of the company, you send some information to all
      the employees, and they all send information back on the same server.
Disadvantages of FTP:
  o   The standard requirement of the industry is that all the FTP transmissions
      should be encrypted. However, not all the FTP providers are equal and not all
      the providers offer encryption. So, we will have to look out for the FTP
      providers that provides encryption.
  o   FTP serves two operations, i.e., to send and receive large files on a network.
      However, the size limit of the file is 2GB that can be sent. It also doesn't allow
      you to run simultaneous transfers to multiple receivers.
  o   Passwords and file contents are sent in clear text that allows unwanted
      eavesdropping. So, it is quite possible that attackers can carry out the brute
      force attack by trying to guess the FTP password.
  o   It is not compatible with every system.
                                       HTTP
  o   HTTP stands for HyperText Transfer Protocol.
  o   It is a protocol used to access the data on the World Wide Web (www).
  o   The HTTP protocol can be used to transfer the data in the form of plain text,
      hypertext, audio, video, and so on.
  o   This protocol is known as HyperText Transfer Protocol because of its
      efficiency that allows us to use in a hypertext environment where there are
      rapid jumps from one document to another document.
  o   HTTP is similar to the FTP as it also transfers the files from one host to
      another host. But, HTTP is simpler than FTP as HTTP uses only one
      connection, i.e., no control connection to transfer the files.
  o   HTTP is used to carry the data in the form of MIME-like format.
  o   HTTP is similar to SMTP as the data is transferred between client and server.
      The HTTP differs from the SMTP in the way the messages are sent from the
      client to the server and from server to the client. SMTP messages are stored
      and forwarded while HTTP messages are delivered immediately.
Features of HTTP:
  o   Connectionless protocol: HTTP is a connectionless protocol. HTTP client
      initiates a request and waits for a response from the server. When the server
      receives the request, the server processes the request and sends back the
      response to the HTTP client after which the client disconnects the connection.
      The connection between client and server exist only during the current request
      and response time only.
  o   Media independent: HTTP protocol is a media independent as data can be
      sent as long as both the client and server know how to handle the data content.
      It is required for both the client and server to specify the content type in
      MIME-type header.
   o   Stateless: HTTP is a stateless protocol as both the client and server know each
       other only during the current request. Due to this nature of the protocol, both
       the client and server do not retain the information between various requests of
       the web pages.
HTTP Transactions
The above figure shows the HTTP transaction between client and server. The client
initiates a transaction by sending a request message to the server. The server replies
to the request message by sending a response message.
Messages
HTTP messages are of two types: request and response. Both the message types
follow the same message format.
Request Message: The request message is sent by the client that consists of a
request line, headers, and sometimes a body.
Response Message: The response message is sent by the server to the client that
consists of a status line, headers, and sometimes a body.
Uniform Resource Locator (URL)
   o   A client that wants to access the document in an internet needs an address and
       to facilitate the access of documents, the HTTP uses the concept of Uniform
       Resource Locator (URL).
   o   The Uniform Resource Locator (URL) is a standard way of specifying any
       kind of information on the internet.
   o   The URL defines four parts: method, host computer, port, and path.
   o   Method: The method is the protocol used to retrieve the document from a
       server. For example, HTTP.
o   Host: The host is the computer where the information is stored, and the
    computer is given an alias name. Web pages are mainly stored in the
    computers and the computers are given an alias name that begins with the
    characters "www". This field is not mandatory.
o   Port: The URL can also contain the port number of the server, but it's an
    optional field. If the port number is included, then it must come between the
    host and path and it should be separated from the host by a colon.
o   Path: Path is the pathname of the file where the information is stored. The
    path itself contain slashes that separate the directories from the subdirectories
    and files.