home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / TCPIP.ZIP / PART1 next >
Text File  |  1987-07-13  |  47KB  |  876 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.                              Introduction
  10.                                   to
  11.                         the Internet Protocols
  12.  
  13.  
  14.  
  15.  
  16.  
  17.                       C                       R
  18.  
  19.                               C       S
  20.                   Computer Science Facilities Group
  21.                               C       I
  22.  
  23.                       L                       S
  24.  
  25.  
  26.                                RUTGERS
  27.                   The State University of New Jersey
  28.  
  29.  
  30.  
  31.  
  32.                              3 July 1987
  33.  
  34. This is an introduction to the Internet networking protocols (TCP/IP).
  35. It  includes  a  summary  of  the  facilities  available   and   brief
  36. descriptions of the major protocols in the family.
  37.  
  38. Copyright  (C)  1987,  Charles  L. Hedrick.  Anyone may reproduce this
  39. document, in whole or in  part,  provided  that:    (1)  any  copy  or
  40. republication  of  the entire document must show Rutgers University as
  41. the source, and must include this notice; and (2)  any  other  use  of
  42. this  material  must reference this manual and Rutgers University, and
  43. the fact that the material is copyright by Charles Hedrick and is used
  44. by permission.
  45.  
  46.  
  47.  
  48. Unix is a trademark of AT&T Technologies, Inc.
  49.  
  50.  
  51.  
  52.                           Table of Contents
  53.  
  54.  
  55.    1. What is TCP/IP?                                                1
  56.    2. General description of the TCP/IP protocols                    5
  57.        2.1 The TCP level                                             7
  58.        2.2 The IP level                                             10
  59.        2.3 The Ethernet level                                       11
  60.    3. Well-known sockets and the applications layer                 12
  61.        3.1 An example application: SMTP                             15
  62.    4. Protocols other than TCP: UDP and ICMP                        17
  63.    5. Keeping track of names and information: the domain system     18
  64.    6. Routing                                                       20
  65.    7. Details about Internet addresses: subnets and broadcasting    21
  66.    8. Datagram fragmentation and reassembly                         23
  67.    9. Ethernet encapsulation: ARP                                   24
  68.    10. Getting more information                                     25
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.                                   i
  108.  
  109.  
  110.  
  111. This document is a brief introduction to TCP/IP, followed by advice on
  112. what to read for more information.  This  is  not  intended  to  be  a
  113. complete  description.    It  can  give  you  a reasonable idea of the
  114. capabilities of the protocols.  But if you need to know any details of
  115. the  technology,  you  will  want  to  read  the  standards  yourself.
  116. Throughout the text, you will find references to the standards, in the
  117. form of "RFC" or "IEN" numbers.  These are document numbers. The final
  118. section of this  document  tells  you  how  to  get  copies  of  those
  119. standards.
  120.  
  121.  
  122.  
  123. 1. What is TCP/IP?
  124.  
  125.  
  126. TCP/IP  is a set of protocols developed to allow cooperating computers
  127. to share resources across a network.  It was developed by a  community
  128. of  researchers centered around the ARPAnet.  Certainly the ARPAnet is
  129. the best-known TCP/IP network.  However as of June, 87, at  least  130
  130. different  vendors  had products that support TCP/IP, and thousands of
  131. networks of all kinds use it.
  132.  
  133. First some basic definitions.  The most accurate name for the  set  of
  134. protocols we are describing is the "Internet protocol suite".  TCP and
  135. IP are two of the protocols in this suite.  (They  will  be  described
  136. below.)    Because  TCP and IP are the best known of the protocols, it
  137. has become common to use the term TCP/IP or IP/TCP  to  refer  to  the
  138. whole  family.  It is probably not worth fighting this habit.  However
  139. this can lead to some oddities.  For example, I  find  myself  talking
  140. about  NFS as being based on TCP/IP, even though it doesn't use TCP at
  141. all.  (It does use IP.  But it  uses  an  alternative  protocol,  UDP,
  142. instead  of TCP.  All of this alphabet soup will be unscrambled in the
  143. following pages.)
  144.  
  145. The Internet is a  collection  of  networks,  including  the  Arpanet,
  146. NSFnet, regional networks such as NYsernet, local networks at a number
  147. of University and research institutions,  and  a  number  of  military
  148. networks.  The term "Internet" applies to this entire set of networks.
  149. The subset of them that is managed by the  Department  of  Defense  is
  150. referred  to  as the "DDN" (Defense Data Network).  This includes some
  151. research-oriented networks, such as  the  Arpanet,  as  well  as  more
  152. strictly  military  ones.    (Because much of the funding for Internet
  153. protocol developments is done via  the  DDN  organization,  the  terms
  154. Internet  and  DDN  can  sometimes  seem  equivalent.)    All of these
  155. networks are connected to each other.  Users can  send  messages  from
  156. any  of  them  to  any other, except where there are security or other
  157. policy restrictions on access.    Officially  speaking,  the  Internet
  158. protocol  documents  are  simply  standards  adopted  by  the Internet
  159. community for its own use.  More recently, the Department  of  Defense
  160. issued a MILSPEC definition of TCP/IP.  This was intended to be a more
  161. formal definition, appropriate for use in  purchasing  specifications.
  162. However  most  of  the  TCP/IP community continues to use the Internet
  163. standards.  The MILSPEC version is intended to be consistent with it.
  164.  
  165. Whatever it is called, TCP/IP is a family of protocols.  A few provide
  166.                                   1
  167.  
  168.  
  169.  
  170. "low-level" functions needed for many applications.  These include IP,
  171. TCP, and UDP.  (These will be described in a bit more  detail  later.)
  172. Others are protocols for doing specific tasks, e.g. transferring files
  173. between computers, sending mail, or finding out who is  logged  in  on
  174. another   computer.      Initially  TCP/IP  was  used  mostly  between
  175. minicomputers or mainframes.  These machines had their own disks,  and
  176. generally  were self-contained.  Thus the most important "traditional"
  177. TCP/IP services are:
  178.  
  179.    - file transfer.  The file transfer protocol (FTP) allows a user on
  180.      any computer to get files from another computer, or to send files
  181.      to another computer.  Security is handled by requiring  the  user
  182.      to  specify  a  user  name  and  password for the other computer.
  183.      Provisions are made for handling file transfer  between  machines
  184.      with different character set, end of line conventions, etc.  This
  185.      is not quite the same thing as more recent "network file  system"
  186.      or  "netbios"  protocols, which will be described below.  Rather,
  187.      FTP is a utility that you run any time you want to access a  file
  188.      on  another  system.    You  use  it to copy the file to your own
  189.      system.  You then work with the local copy.   (See  RFC  959  for
  190.      specifications for FTP.)
  191.  
  192.    - remote  login.    The network terminal protocol (TELNET) allows a
  193.      user to log in on any other computer on the network.  You start a
  194.      remote session by specifying a computer to connect to.  From that
  195.      time until you finish the session, anything you type is  sent  to
  196.      the  other  computer.   Note that you are really still talking to
  197.      your own computer.  But the telnet program effectively makes your
  198.      computer invisible while it is running.  Every character you type
  199.      is sent directly to the other system.  Generally, the  connection
  200.      to  the  remote  computer  behaves much like a dialup connection.
  201.      That is, the remote system will ask you to  log  in  and  give  a
  202.      password, in whatever manner it would normally ask a user who had
  203.      just dialed it up.  When you log off of the other  computer,  the
  204.      telnet  program exits, and you will find yourself talking to your
  205.      own computer.  Microcomputer implementations of telnet  generally
  206.      include  a  terminal  emulator  for some common type of terminal.
  207.      (See RFC's 854 and 855 for specifications for  telnet.    By  the
  208.      way,  the  telnet protocol should not be confused with Telenet, a
  209.      vendor of commercial network services.)
  210.  
  211.    - computer mail.  This allows you to  send  messages  to  users  on
  212.      other  computers.    Originally, people tended to use only one or
  213.      two specific computers.  They  would  maintain  "mail  files"  on
  214.      those machines.  The computer mail system is simply a way for you
  215.      to add a message to another user's mail file.    There  are  some
  216.      problems  with  this  in  an environment where microcomputers are
  217.      used.  The most serious is that a micro is  not  well  suited  to
  218.      receive  computer  mail.    When you send mail, the mail software
  219.      expects to be able  to  open  a  connection  to  the  addressee's
  220.      computer, in order to send the mail.  If this is a microcomputer,
  221.      it may be turned off, or it may be running an  application  other
  222.      than  the mail system.  For this reason, mail is normally handled
  223.      by a larger system, where it is practical to have a  mail  server
  224.      running all the time.  Microcomputer mail software then becomes a
  225.                                   2
  226.  
  227.  
  228.  
  229.      user interface that retrieves mail from the mail  server.    (See
  230.      RFC  821  and  822 for specifications for computer mail.  See RFC
  231.      937 for a protocol designed for microcomputers to use in  reading
  232.      mail from a mail server.)  
  233.  
  234. These  services  should  be  present  in any implementation of TCP/IP,
  235. except that micro-oriented implementations may  not  support  computer
  236. mail.  These traditional applications still play a very important role
  237. in TCP/IP-based networks.  However more recently,  the  way  in  which
  238. networks  are  used has been changing.  The older model of a number of
  239. large, self-sufficient computers is beginning to  change.    Now  many
  240. installations    have    several   kinds   of   computers,   including
  241. microcomputers, workstations, minicomputers, and  mainframes.    These
  242. computers  are  likely  to be configured to perform specialized tasks.
  243. Although people are still likely to work with one  specific  computer,
  244. that  computer  will  call on other systems on the net for specialized
  245. services.  This has  led  to  the  "server/client"  model  of  network
  246. services.    A server is a system that provides a specific service for
  247. the rest of the network.  A client is another system  that  uses  that
  248. service.    (Note  that the server and client need not be on different
  249. computers.  They could be  different  programs  running  on  the  same
  250. computer.)    Here  are  the  kinds  of servers typically present in a
  251. modern computer setup.  Note that these computer services can  all  be
  252. provided within the framework of TCP/IP.
  253.  
  254.    - network  file  systems.   This allows a system to access files on
  255.      another computer in a somewhat more  closely  integrated  fashion
  256.      than FTP.  A network file system provides the illusion that disks
  257.      or other devices from one system are directly connected to  other
  258.      systems.    There  is no need to use a special network utility to
  259.      access a file on another system.  Your computer simply thinks  it
  260.      has  some  extra disk drives.  These extra "virtual" drives refer
  261.      to the other system's disks.    This  capability  is  useful  for
  262.      several different purposes.  It lets you put large disks on a few
  263.      computers, but still give others access to the disk space.  Aside
  264.      from the obvious economic benefits, this allows people working on
  265.      several computers  to  share  common  files.    It  makes  system
  266.      maintenance  and  backup  easier, because you don't have to worry
  267.      about updating  and  backing  up  copies  on  lots  of  different
  268.      machines.    A  number  of  vendors  now  offer  high-performance
  269.      diskless computers.  These computers have no disk drives at  all.
  270.      They  are  entirely dependent upon disks attached to common "file
  271.      servers".   (See  RFC's  1001  and  1002  for  a  description  of
  272.      PC-oriented   NetBIOS   over   TCP.     In  the  workstation  and
  273.      minicomputer area, Sun's Network File System is more likely to be
  274.      used.    Protocol  specifications  for  it are available from Sun
  275.      Microsystems.)
  276.  
  277.    - remote printing.  This allows you to  access  printers  on  other
  278.      computers  as if they were directly attached to yours.  (The most
  279.      commonly used protocol is the remote  lineprinter  protocol  from
  280.      Berkeley  Unix.  Unfortunately, there is no protocol document for
  281.      this.  However the C code is easily obtained  from  Berkeley,  so
  282.      implementations are common.)
  283.  
  284.                                   3
  285.  
  286.  
  287.  
  288.    - remote  execution.   This allows you to request that a particular
  289.      program be run on a different computer.  This is useful when  you
  290.      can  do  most  of  your work on a small computer, but a few tasks
  291.      require the resources of a larger system.  There are a number  of
  292.      different  kinds  of remote execution.  Some operate on a command
  293.      by command basis.  That is, you request that a  specific  command
  294.      or  set  of commands should run on some specific computer.  (More
  295.      sophisticated versions will choose a system that  happens  to  be
  296.      free.)    However  there are also "remote procedure call" systems
  297.      that allow a program to  call  a  subroutine  that  will  run  on
  298.      another  computer.    (There  are  many  protocols  of this sort.
  299.      Berkeley Unix contains two servers to execute commands  remotely:
  300.      rsh  and  rexec.   The man pages describe the protocols that they
  301.      use.  The user-contributed software with Berkeley 4.3 contains  a
  302.      "distributed  shell"  that  will  distribute tasks among a set of
  303.      systems, depending upon load.  Remote procedure  call  mechanisms
  304.      have  been  a  topic  for research for a number of years, so many
  305.      organizations have implementations of such facilities.  The  most
  306.      widespread commercially-supported remote procedure call protocols
  307.      seem to be Xerox's Courier and Sun's RPC.  Protocol documents are
  308.      available  from  Xerox and Sun.  There is a public implementation
  309.      of Courier over TCP as part of the user-contributed software with
  310.      Berkeley  4.3.   An implementation of RPC was posted to Usenet by
  311.      Sun, and also appears as part of  the  user-contributed  software
  312.      with Berkeley 4.3.)
  313.  
  314.    - name  servers.    In  large  installations, there are a number of
  315.      different collections of names that have to  be  managed.    This
  316.      includes  users  and their passwords, names and network addresses
  317.      for computers, and accounts.  It becomes  very  tedious  to  keep
  318.      this data up to date on all of the computers.  Thus the databases
  319.      are kept on a small number of systems.  Other systems access  the
  320.      data over the network.  (RFC 822 and 823 describe the name server
  321.      protocol used to keep track of host names and Internet  addresses
  322.      on  the  Internet.    This  is  now a required part of any TCP/IP
  323.      implementation.  IEN 116 describes an older name server  protocol
  324.      that is used by a few terminal servers and other products to look
  325.      up host names.  Sun's  Yellow  Pages  system  is  designed  as  a
  326.      general  mechanism to handle user names, file sharing groups, and
  327.      other databases commonly used by Unix  systems.    It  is  widely
  328.      available  commercially.    Its  protocol definition is available
  329.      from Sun.)
  330.  
  331.    - terminal servers.  Many installations no longer connect terminals
  332.      directly  to  computers.    Instead they connect them to terminal
  333.      servers.  A terminal server is simply a small computer that  only
  334.      knows  how  to  run  telnet  (or some other protocol to do remote
  335.      login).  If your terminal is  connected  to  one  of  these,  you
  336.      simply  type the name of a computer, and you are connected to it.
  337.      Generally it is possible to have active connections to more  than
  338.      one  computer  at  the  same time.  The terminal server will have
  339.      provisions to switch between connections rapidly, and  to  notify
  340.      you  when  output  is  waiting for another connection.  (Terminal
  341.      servers use the telnet protocol, already mentioned.  However  any
  342.      real terminal server will also have to support name service and a
  343.                                   4
  344.  
  345.  
  346.  
  347.      number of other protocols.)
  348.  
  349.    - network-oriented  window  systems.      Until   recently,   high-
  350.      performance  graphics  programs had to execute on a computer that
  351.      had  a  bit-mapped  graphics  screen  directly  attached  to  it.
  352.      Network  window  systems  allow  a  program to use a display on a
  353.      different computer.  Full-scale network window systems provide an
  354.      interface  that  lets you distribute jobs to the systems that are
  355.      best  suited  to  handle  them,  but  still  give  you  a  single
  356.      graphically-based  user  interface.  (The most widely-implemented
  357.      window system is X. A  protocol  description  is  available  from
  358.      MIT's  Project  Athena.  A reference implementation is publically
  359.      available from MIT.  A number  of  vendors  are  also  supporting
  360.      NeWS,  a window system defined by Sun.  Both of these systems are
  361.      designed to use TCP/IP.)  
  362.  
  363. Note that some of the  protocols  described  above  were  designed  by
  364. Berkeley,  Sun,  or other organizations.  Thus they are not officially
  365. part of the Internet protocol suite.   However  they  are  implemented
  366. using  TCP/IP, just as normal TCP/IP application protocols are.  Since
  367. the protocol definitions are not  considered  proprietary,  and  since
  368. commercially-support  implementations  are  widely  available,  it  is
  369. reasonable to think of these protocols as being  effectively  part  of
  370. the  Internet  suite.   Note that the list above is simply a sample of
  371. the sort of services  available  through  TCP/IP.    However  it  does
  372. contain   the  majority  of  the  "major"  applications.    The  other
  373. commonly-used protocols tend to be specialized facilities for  getting
  374. information  of  various  kinds, such as who is logged in, the time of
  375. day, etc.  However if you need a facility that is not listed here,  we
  376. encourage  you  to  look  through  the  current  edition  of  Internet
  377. Protocols (currently RFC 1011),  which  lists  all  of  the  available
  378. protocols,   and   also   to   look   at  some  of  the  major  TCP/IP
  379. implementations to see what various vendors have added.
  380.  
  381.  
  382.  
  383. 2. General description of the TCP/IP protocols
  384.  
  385.  
  386. TCP/IP is a layered set of protocols.  In  order  to  understand  what
  387. this  means,  it is useful to look at an example.  A typical situation
  388. is sending mail.  First, there is a protocol for mail.  This defines a
  389. set  of  commands which one machine sends to another, e.g. commands to
  390. specify who the sender of the message is, who it is being sent to, and
  391. then  the  text  of  the  message.  However this protocol assumes that
  392. there is a way to communicate  reliably  between  the  two  computers.
  393. Mail,  like  other  application  protocols,  simply  defines  a set of
  394. commands and messages to be sent.  It is designed to be used  together
  395. with  TCP and IP. TCP is responsible for making sure that the commands
  396. get through to the other end.  It keeps track of  what  is  sent,  and
  397. retransmitts anything that did not get through.  If any message is too
  398. large for one datagram, e.g. the text of the mail, TCP will  split  it
  399. up  into  several  datagrams,  and  make  sure  that  they  all arrive
  400. correctly.  Since these functions are needed  for  many  applications,
  401. they are put together into a separate protocol, rather than being part
  402.                                   5
  403.  
  404.  
  405.  
  406. of the specifications for sending mail.   You  can  think  of  TCP  as
  407. forming a library of routines that applications can use when they need
  408. reliable network communications with another computer.  Similarly, TCP
  409. calls  on the services of IP.  Although the services that TCP supplies
  410. are needed by  many  applications,  there  are  still  some  kinds  of
  411. applications  that  don't  need them.  However there are some services
  412. that every application needs.  So these services are put together into
  413. IP.    As  with TCP, you can think of IP as a library of routines that
  414. TCP calls on, but which is also available to applications  that  don't
  415. use  TCP.    This  strategy  of building several levels of protocol is
  416. called "layering".  We think of  the  applications  programs  such  as
  417. mail,  TCP, and IP, as being separate "layers", each of which calls on
  418. the services of the layer below it.   Generally,  TCP/IP  applications
  419. use 4 layers:
  420.  
  421.    - an application protocol such as mail
  422.  
  423.    - a  protocol  such  as  TCP  that  provides  services need by many
  424.      applications
  425.  
  426.    - IP, which provides the basic  service  of  getting  datagrams  to
  427.      their destination
  428.  
  429.    - the  protocols  needed to manage a specific physical medium, such
  430.      as Ethernet or a point to point line.  
  431.  
  432. TCP/IP is based on the "catenet model".  (This is  described  in  more
  433. detail  in  IEN 48.)  This model assumes that there are a large number
  434. of independent networks connected together  by  gateways.    The  user
  435. should  be able to access computers or other resources on any of these
  436. networks.   Datagrams  will  often  pass  through  a  dozen  different
  437. networks  before  getting  to  their  final  destination.  The routing
  438. needed to accomplish this should be completely invisible to the  user.
  439. As  far  as  the  user  is concerned, all he needs to know in order to
  440. access another system is an "Internet address".  This  is  an  address
  441. that looks like 128.6.4.194.  It is actually a 32-bit number.  However
  442. it is normally written as 4 decimal numbers, each representing 8  bits
  443. of  the  address.  (The term "octet" is used by Internet documentation
  444. for such 8-bit chunks.  The term "byte" is not used, because TCP/IP is
  445. supported  by  some computers that have byte sizes other than 8 bits.)
  446. Generally the structure of the  address  gives  you  some  information
  447. about  how  to  get  to  the  system.  For example, 128.6 is a network
  448. number assigned by a central authority to Rutgers University.  Rutgers
  449. uses  the  next  octet  to  indicate  which of the campus Ethernets is
  450. involved.  128.6.4 happens to be an  Ethernet  used  by  the  Computer
  451. Science  Department.    The last octet allows for up to 254 systems on
  452. each Ethernet.  (It is 254 because 0 and  255  are  not  allowed,  for
  453. reasons  that  will  be  discussed  later.)  Note that 128.6.4.194 and
  454. 128.6.5.194 would be different systems.  The structure of an  Internet
  455. address is described in a bit more detail later.
  456.  
  457. Of  course  we  normally  refer  to  systems  by  name, rather than by
  458. Internet address.  When we specify a name, the network software  looks
  459. it  up  in  a  database,  and comes up with the corresponding Internet
  460. address.  Most of the network software deals strictly in terms of  the
  461.                                   6
  462.  
  463.  
  464.  
  465. address.  (RFC 882 describes the name server technology used to handle
  466. this lookup.)
  467.  
  468. TCP/IP is  built  on  "connectionless"  technology.    Information  is
  469. transfered  as  a sequence of "datagrams".  A datagram is a collection
  470. of data that is sent as a single message.  Each of these datagrams  is
  471. sent  through  the network individually.  There are provisions to open
  472. connections (i.e.  to start a conversation that will continue for some
  473. time).    However at some level, information from those connections is
  474. broken up into datagrams, and  those  datagrams  are  treated  by  the
  475. network  as  completely  separate.    For example, suppose you want to
  476. transfer a 15000 octet file.  Most networks can't handle a 15000 octet
  477. datagram.   So the protocols will break this up into something like 30
  478. 500-octet datagrams.  Each of these datagrams  will  be  sent  to  the
  479. other  end.    At  that point, they will be put back together into the
  480. 15000-octet file.  However while those datagrams are in  transit,  the
  481. network doesn't know that there is any connection between them.  It is
  482. perfectly possible  that  datagram  14  will  actually  arrive  before
  483. datagram  13.    It is also possible that somewhere in the network, an
  484. error will occur, and some datagram won't get through at all.  In that
  485. case, that datagram has to be sent again.
  486.  
  487. Note  by  the way that the terms "datagram" and "packet" often seem to
  488. be nearly interchangable.  Technically, datagram is the right word  to
  489. use  when  describing  TCP/IP.  A datagram is a unit of data, which is
  490. what the protocols deal with.  A packet is a physical thing, appearing
  491. on an Ethernet or some wire.  In most cases a packet simply contains a
  492. datagram, so there is  very  little  difference.    However  they  can
  493. differ.  When TCP/IP is used on top of X.25, the X.25 interface breaks
  494. the datagrams up into 128-byte packets.   This  is  invisible  to  IP,
  495. because  the  packets  are put back together into a single datagram at
  496. the other end before being processed by TCP/IP.  So in this case,  one
  497. IP  datagram  would  be carried by several packets.  However with most
  498. media, there are efficiency advantages to  sending  one  datagram  per
  499. packet, and so the distinction tends to vanish.
  500.  
  501.  
  502.  
  503. 2.1 The TCP level
  504.  
  505.  
  506. Two separate protocols are involved in handling TCP/IP datagrams.  TCP
  507. (the "transmission control protocol") is responsible for  breaking  up
  508. the  message  into  datagrams,  reassembling  them  at  the other end,
  509. resending anything that gets lost, and  putting  things  back  in  the
  510. right  order.  IP (the "internet protocol") is responsible for routing
  511. individual datagrams.  It may seem like TCP is  doing  all  the  work.
  512. And  in  small networks that is true.  However in the Internet, simply
  513. getting a datagram to its  destination  can  be  a  complex  job.    A
  514. connection  may require the datagram to go through several networks at
  515. Rutgers, a serial line to the John von Neuman Supercomputer Center,  a
  516. couple  of Ethernets there, a series of 56Kbaud phone lines to another
  517. NSFnet site, and more Ethernets on another campus.  Keeping  track  of
  518. the  routes  to all of the destinations and handling incompatibilities
  519. among different transport media turns out to be a complex job.    Note
  520.                                   7
  521.  
  522.  
  523.  
  524. that  the  interface  between TCP and IP is fairly simple.  TCP simply
  525. hands IP a datagram with a destination.   IP  doesn't  know  how  this
  526. datagram relates to any datagram before it or after it.
  527.  
  528. It  may  have occurred to you that something is missing here.  We have
  529. talked about Internet addresses, but not about how you keep  track  of
  530. multiple  connections  to  a given system.  Clearly it isn't enough to
  531. get a datagram to the right  destination.    TCP  has  to  know  which
  532. connection  this  datagram  is  part  of.  This task is referred to as
  533. "demultiplexing."  In fact, there are several levels of demultiplexing
  534. going  on in TCP/IP.  The information needed to do this demultiplexing
  535. is contained in a series of "headers".  A header is simply a few extra
  536. octets  tacked  onto  the  beginning of a datagram by some protocol in
  537. order to keep track of it.  It's a lot like putting a letter  into  an
  538. envelope  and  putting  an  address  on  the  outside of the envelope.
  539. Except with modern networks it happens several times.  It's  like  you
  540. put the letter into a little envelope, your secretary puts that into a
  541. somewhat bigger envelope, the campus mail center  puts  that  envelope
  542. into a still bigger one, etc.  Here is an overview of the headers that
  543. get stuck on a message that passes through a typical TCP/IP network:
  544.  
  545. We start with a single data stream, say a file you are trying to  send
  546. to some other computer:  
  547.  
  548.    ......................................................
  549.  
  550. TCP  breaks  it  up into manageable chunks.  (In order to do this, TCP
  551. has to know how large a datagram your network can handle.    Actually,
  552. the TCP's at each end say how big a datagram they can handle, and then
  553. they pick the smallest size.)  
  554.  
  555.    ....   ....   ....   ....   ....   ....   ....   ....
  556.  
  557. TCP puts a header at the front of each datagram.  This header actually
  558. contains  at least 20 octets, but the most important ones are a source
  559. and destination "port number" and  a  "sequence  number".    The  port
  560. numbers  are used to keep track of different conversations.  Suppose 3
  561. different people are transferring files.  Your TCP might allocate port
  562. numbers 1000, 1001, and 1002 to these transfers.  When you are sending
  563. a datagram, this becomes the "source" port number, since you  are  the
  564. source  of  the  datagram.    Of  course  the TCP at the other end has
  565. assigned a port number of its own for the conversation.  Your TCP  has
  566. to  know the port number used by the other end as well.  (It finds out
  567. when the connection starts, as we will explain below.)  It  puts  this
  568. in  the  "destination" port field.  Of course if the other end sends a
  569. datagram back to you, the source and destination port numbers will  be
  570. reversed,  since  then  it  will  be  the  source  and you will be the
  571. destination.  Each datagram has a sequence number.  This  is  used  so
  572. that  the  other  end  can make sure that it gets the datagrams in the
  573. right  order,  and  that  it  hasn't  missed  any.    (See   the   TCP
  574. specification for details.)  TCP doesn't number the datagrams, but the
  575. octets.  So if there are 500 octets of  data  in  each  datagram,  the
  576. first datagram might be numbered 0, the second 500, the next 1000, the
  577. next 1500, etc.  Finally, I will mention the  Checksum.    This  is  a
  578. number  that  is  computed by adding up all the octets in the datagram
  579.                                   8
  580.  
  581.  
  582.  
  583. (more or less - see the TCP spec).  The result is put in  the  header.
  584. TCP  at  the other end computes the checksum again.  If they disagree,
  585. then something bad happened to the datagram in transmission, and it is
  586. thrown away.  So here's what the datagram looks like now.
  587.  
  588.     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  589.     |          Source Port          |       Destination Port        |
  590.     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  591.     |                        Sequence Number                        |
  592.     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  593.     |                    Acknowledgment Number                      |
  594.     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  595.     |  Data |           |U|A|P|R|S|F|                               |
  596.     | Offset| Reserved  |R|C|S|S|Y|I|            Window             |
  597.     |       |           |G|K|H|T|N|N|                               |
  598.     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  599.     |           Checksum            |         Urgent Pointer        |
  600.     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  601.     |   your data ... next 500 octets                               |
  602.     |   ......                                                      |
  603.  
  604. If  we abbreviate the TCP header as "T", the whole file now looks like
  605. this:
  606.  
  607.    T....   T....   T....   T....   T....   T....   T....
  608.  
  609. You will note that there are items in  the  header  that  I  have  not
  610. described  above.    They  are  generally  involved  with managing the
  611. connection.  In order to make sure the datagram  has  arrived  at  its
  612. destination,  the  recipient  has  to  send back an "acknowledgement".
  613. This is a datagram whose "Acknowledgement number" field is filled  in.
  614. For  example,  sending  a  packet  with  an  acknowledgement  of  1500
  615. indicates that you have received all the data up to octet number 1500.
  616. If  the  sender  doesn't  get  an  acknowledgement within a reasonable
  617. amount of time, it sends the data  again.    The  window  is  used  to
  618. control  how  much  data can be in transit at any one time.  It is not
  619. practical to wait for each datagram to be acknowledged before  sending
  620. the  next  one.    That would slow things down too much.  On the other
  621. hand, you can't just keep sending, or a fast  computer  might  overrun
  622. the  capacity  of  a slow one to absorb data.  Thus each end indicates
  623. how much new data it is currently prepared to absorb  by  putting  the
  624. number  of  octets  in  its  "Window" field.  As the computer receives
  625. data, the amount of space left in its window decreases.  When it  goes
  626. to  zero, the sender has to stop.  As the receiver processes the data,
  627. it increases its window, indicating that it is ready  to  accept  more
  628. data.  Often the same datagram can be used to acknowledge receipt of a
  629. set of data and to give permission for  additional  new  data  (by  an
  630. updated  window).  The "Urgent" field allows one end to tell the other
  631. to skip ahead in its processing to a particular octet.  This is  often
  632. useful  for  handling asynchronous events, for example when you type a
  633. control character or other command that interrupts output.  The  other
  634. fields are beyond the scope of this document.
  635.  
  636.  
  637.  
  638.                                   9
  639.  
  640.  
  641.  
  642. 2.2 The IP level
  643.  
  644.  
  645. TCP  sends each of these datagrams to IP.  Of course it has to tell IP
  646. the Internet address of the computer at the other end.  Note that this
  647. is  all  IP  is concerned about.  It doesn't care about what is in the
  648. datagram, or even in the TCP header.  IP's job is  simply  to  find  a
  649. route for the datagram and get it to the other end.  In order to allow
  650. gateways or other intermediate systems to  forward  the  datagram,  it
  651. adds  its  own  header.  The main things in this header are the source
  652. and destination Internet address (32-bit addresses, like 128.6.4.194),
  653. the  protocol  number,  and  another  checksum.    The source Internet
  654. address is simply the address of your machine.  (This is necessary  so
  655. the  other  end  knows where the datagram came from.)  The destination
  656. Internet address is the address  of  the  other  machine.    (This  is
  657. necessary  so  any  gateways  in  the  middle  know where you want the
  658. datagram to go.)  The protocol number tells IP at  the  other  end  to
  659. send  the  datagram  to TCP.  Although most IP traffic uses TCP, there
  660. are other protocols that can use IP, so you  have  to  tell  IP  which
  661. protocol  to send the datagram to.  Finally, the checksum allows IP at
  662. the other end to verify that the header  wasn't  damaged  in  transit.
  663. Note  that TCP and IP have separate checksums.  IP needs to be able to
  664. verify that the header didn't get damaged in transit, or it could send
  665. a  message to the wrong place.  For reasons not worth discussing here,
  666. it is both more efficient and safer to have  TCP  compute  a  separate
  667. checksum  for  the  TCP  header  and  data.  Once IP has tacked on its
  668. header, here's what the message looks like:
  669.  
  670.     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  671.     |Version|  IHL  |Type of Service|          Total Length         |
  672.     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  673.     |         Identification        |Flags|      Fragment Offset    |
  674.     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  675.     |  Time to Live |    Protocol   |         Header Checksum       |
  676.     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  677.     |                       Source Address                          |
  678.     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  679.     |                    Destination Address                        |
  680.     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  681.     |  TCP header, then your data ......                            |
  682.     |                                                               |
  683.  
  684. If we represent the IP header by an "I",  your  file  now  looks  like
  685. this:  
  686.  
  687.    IT....   IT....   IT....   IT....   IT....   IT....   IT....
  688.  
  689. Again,  the  header contains some additional fields that have not been
  690. discussed.  Most of them are beyond the scope of this document.    The
  691. flags  and fragment offset are used to keep track of the pieces when a
  692. datagram has to be split up.   This  can  happen  when  datagrams  are
  693. forwarded through a network for which they are too big.  (This will be
  694. discussed a bit more below.)  The time to live is  a  number  that  is
  695. decremented  whenever  the  datagram passes through a system.  When it
  696. goes to zero, the datagram is discarded.  This is done in case a  loop
  697.                                   10
  698.  
  699.  
  700.  
  701. develops  in the system somehow.  Of course this should be impossible,
  702. but  well-designed  networks  are  built  to  cope  with  "impossible"
  703. conditions.
  704.  
  705. At this point, it's possible that no more headers are needed.  If your
  706. computer happens to have a direct phone  line  connecting  it  to  the
  707. destination  computer,  or  to  a  gateway,  it  may  simply  send the
  708. datagrams out on the line (though likely a synchronous  protocol  such
  709. as  HDLC  would be used, and it would add at least a few octets at the
  710. beginning and end).
  711.  
  712.  
  713.  
  714. 2.3 The Ethernet level
  715.  
  716.  
  717. However most of our networks these days use Ethernet.  So now we  have
  718. to  describe  Ethernet's headers.  Unfortunately, Ethernet has its own
  719. addresses.  The people who designed Ethernet wanted to make sure  that
  720. no  two  machines  would  end  up  with  the  same  Ethernet  address.
  721. Furthermore, they  didn't  want  the  user  to  have  to  worry  about
  722. assigning  addresses.    So  each  Ethernet  controller  comes with an
  723. address builtin from the factory.  In order to  make  sure  that  they
  724. would  never have to reuse addresses, the Ethernet designers allocated
  725. 48 bits for the Ethernet address.  People who make Ethernet  equipment
  726. have  to  register  with  a  central  authority, to make sure that the
  727. numbers they assign don't overlap any other manufacturer.  Ethernet is
  728. a "broadcast medium".  That is, it is in effect like an old party line
  729. telephone.  When you send a packet out on the Ethernet, every  machine
  730. on  the  network sees the packet.  So something is needed to make sure
  731. that the right machine gets it.  As you might guess, this involves the
  732. Ethernet  header.    Every  Ethernet packet has a 14-octet header that
  733. includes the source and destination Ethernet address, and a type code.
  734. Each machine is supposed to pay attention only to packets with its own
  735. Ethernet address in the destination field.  (It's  perfectly  possible
  736. to  cheat,  which  is  one reason that Ethernet communications are not
  737. terribly secure.)  Note  that  there  is  no  connection  between  the
  738. Ethernet address and the Internet address.  Each machine has to have a
  739. table of what Ethernet address corresponds to what  Internet  address.
  740. (We  will  describe  how  this  table is constructed a bit later.)  In
  741. addition to the addresses, the header contains a type code.  The  type
  742. code is to allow for several different protocol families to be used on
  743. the same network.  So you can use TCP/IP, DECnet, Xerox  NS,  etc.  at
  744. the  same  time.   Each of them will put a different value in the type
  745. field.  Finally,  there  is  a  checksum.    The  Ethernet  controller
  746. computes a checksum of the entire packet.  When the other end receives
  747. the packet, it recomputes the checksum, and throws the packet away  if
  748. the  answer  disagrees  with the original.  The checksum is put on the
  749. end of the packet, not in the header.  The final result is  that  your
  750. message looks like this:
  751.  
  752.  
  753.  
  754.  
  755.  
  756.                                   11
  757.  
  758.  
  759.  
  760.     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  761.     |       Ethernet destination address (first 32 bits)            |
  762.     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  763.     | Ethernet dest (last 16 bits)  |Ethernet source (first 16 bits)|
  764.     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  765.     |       Ethernet source address (last 32 bits)                  |
  766.     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  767.     |        Type code              |
  768.     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  769.     |  IP header, then TCP header, then your data                   |
  770.     |                                                               |
  771.         ...
  772.     |                                                               |
  773.     |   end of your data                                            |
  774.     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  775.     |                       Ethernet Checksum                       |
  776.     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  777.  
  778. If  we  represent  the  Ethernet  header  with  "E",  and the Ethernet
  779. checksum with "C", your file now looks like this:  
  780.  
  781.    EIT....C   EIT....C   EIT....C   EIT....C   EIT....C
  782.  
  783. When these packets are received by the other end, of  course  all  the
  784. headers  are  removed.    The  Ethernet interface removes the Ethernet
  785. header and the checksum.  It looks at the type code.  Since  the  type
  786. code  is the one assigned to IP, the Ethernet device driver passes the
  787. datagram up to IP.  IP removes the IP header.   It  looks  at  the  IP
  788. protocol  field.    Since  the  protocol  type  is  TCP, it passes the
  789. datagram up to TCP.  TCP now looks at the sequence number.    It  uses
  790. the  sequence  numbers  and  other  information  to  combine  all  the
  791. datagrams into the original file.
  792.  
  793. The ends our initial summary of TCP/IP.  There are still some  crucial
  794. concepts we haven't gotten to, so we'll now go back and add details in
  795. several areas.  (For detailed descriptions of the items discussed here
  796. see,  RFC  793  for  TCP,  RFC  791  for IP, and RFC's 894 and 826 for
  797. sending IP over Ethernet.)
  798.  
  799.  
  800.  
  801. 3. Well-known sockets and the applications layer
  802.  
  803.  
  804. So far, we have described how a stream  of  data  is  broken  up  into
  805. datagrams,  sent  to another computer, and put back together.  However
  806. something more is needed  in  order  to  accomplish  anything  useful.
  807. There  has  to  be  a  way for you to open a connection to a specified
  808. computer, log into it, tell it what file you  want,  and  control  the
  809. transmission  of  the  file.   (If you have a different application in
  810. mind, e.g. computer mail, some analogous protocol is needed.)  This is
  811. done  by  "application  protocols".  The application protocols run "on
  812. top" of TCP/IP.  That is, when they want to send a message, they  give
  813. the  message  to  TCP.   TCP makes sure it gets delivered to the other
  814. end.  Because TCP and IP take care of all the networking details,  the
  815.                                   12
  816.  
  817.  
  818.  
  819. applications  protocols can treat a network connection as if it were a
  820. simple byte stream, like a terminal or phone line.
  821.  
  822. Before going into more details about applications programs, we have to
  823. describe how you find an application.  Suppose you want to send a file
  824. to a computer whose Internet address  is  128.6.4.7.    To  start  the
  825. process,  you  need  more than just the Internet address.  You have to
  826. connect to the FTP server at the  other  end.    In  general,  network
  827. programs  are  specialized  for a specific set of tasks.  Most systems
  828. have separate programs  to  handle  file  transfers,  remote  terminal
  829. logins, mail, etc.  When you connect to 128.6.4.7, you have to specify
  830. that you want to talk to the FTP server.    This  is  done  by  having
  831. "well-known  sockets"  for  each  server.    Recall that TCP uses port
  832. numbers to keep track of  individual  conversations.    User  programs
  833. normally  use more or less random port numbers.  However specific port
  834. numbers are assigned to the programs that sit  waiting  for  requests.
  835. For  example,  if  you  want  to send a file, you will start a program
  836. called "ftp".  It will open a connection using some random number, say
  837. 1234,  for  the  port number on its end.  However it will specify port
  838. number 21 for the other end.  This is the official port number for the
  839. FTP server.  Note that there are two different programs involved.  You
  840. run ftp on your side.  This is a program designed to  accept  commands
  841. from  your  terminal  and  pass them on to the other end.  The program
  842. that you talk to on the other machine  is  the  FTP  server.    It  is
  843. designed  to  accept commands from the network connection, rather than
  844. an interactive terminal.  There is no need for your program to  use  a
  845. well-known  socket  number  for  itself.  Nobody is trying to find it.
  846. However the servers have to have well-known numbers,  so  that  people
  847. can  open  connections  to  them and start sending them commands.  The
  848. official  port  numbers  for  each  program  are  given  in  "Assigned
  849. Numbers".
  850.  
  851. Note  that  a  connection is actually described by a set of 4 numbers:
  852. the Internet address at each end, and the TCP port number at each end.
  853. Every  datagram  has  all  four of those numbers in it.  (The Internet
  854. addresses are in the IP header, and the TCP port numbers  are  in  the
  855. TCP header.)  In order to keep things straight, no two connections can
  856. have the same set of numbers.  However it is enough for any one number
  857. to  be  different.    For  example,  it  is perfectly possible for two
  858. different users on a machine to be sending files  to  the  same  other
  859. machine.    This  could  result  in  connections  with  the  following
  860. parameters:
  861.  
  862.                    Internet addresses         TCP ports
  863.     connection 1  128.6.4.194, 128.6.4.7      1234, 21
  864.     connection 2  128.6.4.194, 128.6.4.7      1235, 21
  865.  
  866. Since the same machines are involved, the Internet addresses  are  the
  867. same.    Since  they  are  both  doing  file transfers, one end of the
  868. connection involves the well-known port number  for  FTP.    The  only
  869. thing  that  differs is the port number for the program that the users
  870. are running.  That's enough of a difference.  Generally, at least  one
  871. end  of  the  connection asks the network software to assign it a port
  872. number that is guaranteed to be unique.   Normally,  it's  the  user's
  873. end, since the server has to use a well-known number.
  874.                                   13
  875.  
  876.