1
0
Fork 0
cl-sites/w3.cs.jmu.edu/kirkpams/OpenCSF/Books/csf/html/AppBroadcast.html
2025-01-28 10:11:14 +01:00

451 lines
32 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>4.7. Application-Layer Broadcasting: DHCP &mdash; Computer Systems Fundamentals</title>
<link rel="stylesheet" href="_static/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous" />
<link rel="stylesheet" href="_static/css/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/normalize.css" type="text/css" />
<link rel="stylesheet" href="../../../JSAV/css/JSAV.css" type="text/css" />
<link rel="stylesheet" href="../../../lib/odsaMOD-min.css" type="text/css" />
<link rel="stylesheet" href="_static/css/jquery-1.11.4-smoothness-ui.css" type="text/css" />
<link rel="stylesheet" href="../../../lib/odsaStyle-min.css" type="text/css" />
<link rel="stylesheet" href="_static/css/csf.css" type="text/css" />
<style>
.underline { text-decoration: underline; }
</style>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '0.4.1',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$','$'], ['\\(','\\)']],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEscapes: true
},
"HTML-CSS": {
scale: "80"
}
});
</script>
<link rel="shortcut icon" href="_static/favicon.ico"/>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="index" title="Computer Systems Fundamentals" href="index.html" />
<link rel="next" title="8. Extended Example: CGI Web Server" href="Extended4CGI.html" />
<link rel="prev" title="6. UDP Socket Programming: DNS" href="UDPSockets.html" />
</head><body>
<nav class="navbar navbar-expand-md navbar-dark navbar-custom fixed-top">
<a class="navbar-brand py-0" href="index.html"><img src="_static/CSF-Logo-Square-Text.png" alt="OpenCSF Logo" height="40em" class="py-1 px-2 mb-0 align-center rounded-lg bg-white" /></a>
<!-- Show a navbar toggler on mobile -->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#defaultNavbars" aria-controls="defaultNavbars" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="defaultNavbars">
<ul class="navbar-nav mr-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle jmu-gold rounded" href="AppBroadcast.html#" id="navbarDropdownChapters" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Contents</a>
<div class="dropdown-menu scrollable-menu" role="menu" aria-labelledby="navbarDropdownChapters">
<a class="dropdown-item" tabindex="-1" href="AppBroadcast.html#"><b>Chapter 1</b></a>
<a class="dropdown-item" href="IntroConcSysOverview.html">&nbsp;&nbsp;&nbsp;1.1. Introduction to Concurrent Systems</a>
<a class="dropdown-item" href="SysAndModels.html">&nbsp;&nbsp;&nbsp;1.2. Systems and Models</a>
<a class="dropdown-item" href="Themes.html">&nbsp;&nbsp;&nbsp;1.3. Themes and Guiding Principles</a>
<a class="dropdown-item" href="Architectures.html">&nbsp;&nbsp;&nbsp;1.4. System Architectures</a>
<a class="dropdown-item" href="StateModels.html">&nbsp;&nbsp;&nbsp;1.5. State Models in UML</a>
<a class="dropdown-item" href="SequenceModels.html">&nbsp;&nbsp;&nbsp;1.6. Sequence Models in UML</a>
<a class="dropdown-item" href="StateModelImplementation.html">&nbsp;&nbsp;&nbsp;1.7. Extended Example: State Model Implementation</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item disabled"><b>Chapter 2</b></a>
<a class="dropdown-item" href="ProcessesOverview.html">&nbsp;&nbsp;&nbsp;2.1. Processes and OS Basics</a>
<a class="dropdown-item" href="Multiprogramming.html">&nbsp;&nbsp;&nbsp;2.2. Processes and Multiprogramming</a>
<a class="dropdown-item" href="KernelMechanics.html">&nbsp;&nbsp;&nbsp;2.3. Kernel Mechanics</a>
<a class="dropdown-item" href="Syscall.html">&nbsp;&nbsp;&nbsp;2.4. System Call Interface</a>
<a class="dropdown-item" href="ProcessCycle.html">&nbsp;&nbsp;&nbsp;2.5. Process Life Cycle</a>
<a class="dropdown-item" href="UnixFile.html">&nbsp;&nbsp;&nbsp;2.6. The UNIX File Abstraction</a>
<a class="dropdown-item" href="EventsSignals.html">&nbsp;&nbsp;&nbsp;2.7. Events and Signals</a>
<a class="dropdown-item" href="Extended2Processes.html">&nbsp;&nbsp;&nbsp;2.8. Extended Example: Listing Files with Processes</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item disabled"><b>Chapter 3</b></a>
<a class="dropdown-item" href="IPCOverview.html">&nbsp;&nbsp;&nbsp;3.1. Concurrency with IPC</a>
<a class="dropdown-item" href="IPCModels.html">&nbsp;&nbsp;&nbsp;3.2. IPC Models</a>
<a class="dropdown-item" href="Pipes.html">&nbsp;&nbsp;&nbsp;3.3. Pipes and FIFOs</a>
<a class="dropdown-item" href="MMap.html">&nbsp;&nbsp;&nbsp;3.4. Shared Memory With Memory-mapped Files</a>
<a class="dropdown-item" href="POSIXvSysV.html">&nbsp;&nbsp;&nbsp;3.5. POSIX vs. System V IPC</a>
<a class="dropdown-item" href="MQueues.html">&nbsp;&nbsp;&nbsp;3.6. Message Passing With Message Queues</a>
<a class="dropdown-item" href="ShMem.html">&nbsp;&nbsp;&nbsp;3.7. Shared Memory</a>
<a class="dropdown-item" href="IPCSems.html">&nbsp;&nbsp;&nbsp;3.8. Semaphores</a>
<a class="dropdown-item" href="Extended3Bash.html">&nbsp;&nbsp;&nbsp;3.9. Extended Example: Bash-lite: A Simple Command-line Shell</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item disabled"><b>Chapter 4</b></a>
<a class="dropdown-item" href="SocketsOverview.html">&nbsp;&nbsp;&nbsp;4.1. Networked Concurrency</a>
<a class="dropdown-item" href="FiveLayer.html">&nbsp;&nbsp;&nbsp;4.2. The TCP/IP Internet Model</a>
<a class="dropdown-item" href="NetApps.html">&nbsp;&nbsp;&nbsp;4.3. Network Applications and Protocols</a>
<a class="dropdown-item" href="Sockets.html">&nbsp;&nbsp;&nbsp;4.4. The Socket Interface</a>
<a class="dropdown-item" href="TCPSockets.html">&nbsp;&nbsp;&nbsp;4.5. TCP Socket Programming: HTTP</a>
<a class="dropdown-item" href="UDPSockets.html">&nbsp;&nbsp;&nbsp;4.6. UDP Socket Programming: DNS</a>
<a class="dropdown-item" href="AppBroadcast.html">&nbsp;&nbsp;&nbsp;4.7. Application-Layer Broadcasting: DHCP</a>
<a class="dropdown-item" href="Extended4CGI.html">&nbsp;&nbsp;&nbsp;4.8. Extended Example: CGI Web Server</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item disabled"><b>Chapter 5</b></a>
<a class="dropdown-item" href="InternetOverview.html">&nbsp;&nbsp;&nbsp;5.1. The Internet and Connectivity</a>
<a class="dropdown-item" href="AppLayer.html">&nbsp;&nbsp;&nbsp;5.2. Application Layer: Overlay Networks</a>
<a class="dropdown-item" href="TransLayer.html">&nbsp;&nbsp;&nbsp;5.3. Transport Layer</a>
<a class="dropdown-item" href="NetSec.html">&nbsp;&nbsp;&nbsp;5.4. Network Security Fundamentals</a>
<a class="dropdown-item" href="NetLayer.html">&nbsp;&nbsp;&nbsp;5.5. Network Layer: IP</a>
<a class="dropdown-item" href="LinkLayer.html">&nbsp;&nbsp;&nbsp;5.6. Link Layer</a>
<a class="dropdown-item" href="Wireless.html">&nbsp;&nbsp;&nbsp;5.7. Wireless Connectivity: Wi-Fi, Bluetooth, and Zigbee</a>
<a class="dropdown-item" href="Extended5DNS.html">&nbsp;&nbsp;&nbsp;5.8. Extended Example: DNS client</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item disabled"><b>Chapter 6</b></a>
<a class="dropdown-item" href="ThreadsOverview.html">&nbsp;&nbsp;&nbsp;6.1. Concurrency with Multithreading</a>
<a class="dropdown-item" href="ProcVThreads.html">&nbsp;&nbsp;&nbsp;6.2. Processes vs. Threads</a>
<a class="dropdown-item" href="RaceConditions.html">&nbsp;&nbsp;&nbsp;6.3. Race Conditions and Critical Sections</a>
<a class="dropdown-item" href="POSIXThreads.html">&nbsp;&nbsp;&nbsp;6.4. POSIX Thread Library</a>
<a class="dropdown-item" href="ThreadArgs.html">&nbsp;&nbsp;&nbsp;6.5. Thread Arguments and Return Values</a>
<a class="dropdown-item" href="ImplicitThreads.html">&nbsp;&nbsp;&nbsp;6.6. Implicit Threading and Language-based Threads</a>
<a class="dropdown-item" href="Extended6Input.html">&nbsp;&nbsp;&nbsp;6.7. Extended Example: Keyboard Input Listener</a>
<a class="dropdown-item" href="Extended6Primes.html">&nbsp;&nbsp;&nbsp;6.8. Extended Example: Concurrent Prime Number Search</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item disabled"><b>Chapter 7</b></a>
<a class="dropdown-item" href="SynchOverview.html">&nbsp;&nbsp;&nbsp;7.1. Synchronization Primitives</a>
<a class="dropdown-item" href="CritSect.html">&nbsp;&nbsp;&nbsp;7.2. Critical Sections and Peterson's Solution</a>
<a class="dropdown-item" href="Locks.html">&nbsp;&nbsp;&nbsp;7.3. Locks</a>
<a class="dropdown-item" href="Semaphores.html">&nbsp;&nbsp;&nbsp;7.4. Semaphores</a>
<a class="dropdown-item" href="Barriers.html">&nbsp;&nbsp;&nbsp;7.5. Barriers</a>
<a class="dropdown-item" href="Condvars.html">&nbsp;&nbsp;&nbsp;7.6. Condition Variables</a>
<a class="dropdown-item" href="Deadlock.html">&nbsp;&nbsp;&nbsp;7.7. Deadlock</a>
<a class="dropdown-item" href="Extended7Events.html">&nbsp;&nbsp;&nbsp;7.8. Extended Example: Event Log File</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item disabled"><b>Chapter 8</b></a>
<a class="dropdown-item" href="SynchProblemsOverview.html">&nbsp;&nbsp;&nbsp;8.1. Synchronization Patterns and Problems</a>
<a class="dropdown-item" href="SynchDesign.html">&nbsp;&nbsp;&nbsp;8.2. Basic Synchronization Design Patterns</a>
<a class="dropdown-item" href="ProdCons.html">&nbsp;&nbsp;&nbsp;8.3. Producer-Consumer Problem</a>
<a class="dropdown-item" href="ReadWrite.html">&nbsp;&nbsp;&nbsp;8.4. Readers-Writers Problem</a>
<a class="dropdown-item" href="DiningPhil.html">&nbsp;&nbsp;&nbsp;8.5. Dining Philosophers Problem and Deadlock</a>
<a class="dropdown-item" href="CigSmokers.html">&nbsp;&nbsp;&nbsp;8.6. Cigarette Smokers Problem and the Limits of Semaphores and Locks</a>
<a class="dropdown-item" href="Extended8ModExp.html">&nbsp;&nbsp;&nbsp;8.7. Extended Example: Parallel Modular Exponentiation</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item disabled"><b>Chapter 9</b></a>
<a class="dropdown-item" href="ParallelDistributedOverview.html">&nbsp;&nbsp;&nbsp;9.1. Parallel and Distributed Systems</a>
<a class="dropdown-item" href="ParVConc.html">&nbsp;&nbsp;&nbsp;9.2. Parallelism vs. Concurrency</a>
<a class="dropdown-item" href="ParallelDesign.html">&nbsp;&nbsp;&nbsp;9.3. Parallel Design Patterns</a>
<a class="dropdown-item" href="Scaling.html">&nbsp;&nbsp;&nbsp;9.4. Limits of Parallelism and Scaling</a>
<a class="dropdown-item" href="DistTiming.html">&nbsp;&nbsp;&nbsp;9.5. Timing in Distributed Environments</a>
<a class="dropdown-item" href="DistDataStorage.html">&nbsp;&nbsp;&nbsp;9.6. Reliable Data Storage and Location</a>
<a class="dropdown-item" href="DistConsensus.html">&nbsp;&nbsp;&nbsp;9.7. Consensus in Distributed Systems</a>
<a class="dropdown-item" href="Extended9Blockchain.html">&nbsp;&nbsp;&nbsp;9.8. Extended Example: Blockchain Proof-of-Work</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item disabled"><b>Appendix A</b></a>
<a class="dropdown-item" href="CLangOverview.html">&nbsp;&nbsp;&nbsp;A.1. C Language Reintroduction</a>
<a class="dropdown-item" href="Debugging.html">&nbsp;&nbsp;&nbsp;A.2. Documentation and Debugging</a>
<a class="dropdown-item" href="BasicTypes.html">&nbsp;&nbsp;&nbsp;A.3. Basic Types and Pointers</a>
<a class="dropdown-item" href="Arrays.html">&nbsp;&nbsp;&nbsp;A.4. Arrays, Structs, Enums, and Type Definitions</a>
<a class="dropdown-item" href="Functions.html">&nbsp;&nbsp;&nbsp;A.5. Functions and Scope</a>
<a class="dropdown-item" href="Pointers.html">&nbsp;&nbsp;&nbsp;A.6. Pointers and Dynamic Allocation</a>
<a class="dropdown-item" href="Strings.html">&nbsp;&nbsp;&nbsp;A.7. Strings</a>
<a class="dropdown-item" href="FunctionPointers.html">&nbsp;&nbsp;&nbsp;A.8. Function Pointers</a>
<a class="dropdown-item" href="Files.html">&nbsp;&nbsp;&nbsp;A.9. Files</a>
</div>
</li>
</ul>
</div>
<ul class="navbar-nav flex-row ml-md-auto d-none d-md-flex">
<li class="nav-item"><a class="nav-link jmu-gold" href="https://w3.cs.jmu.edu/kirkpams/OpenCSF/Books/csf/source/AppBroadcast.rst"
target="_blank" rel="nofollow">Show Source</a></li>
</ul>
</nav>
<div class="container center">
«&#160;&#160;<a id="prevmod" href="UDPSockets.html">4.6. UDP Socket Programming: DNS</a>
&#160;&#160;::&#160;&#160;
<a class="uplink" href="index.html">Contents</a>
&#160;&#160;::&#160;&#160;
<a id="nextmod" href="Extended4CGI.html">4.8. Extended Example: CGI Web Server</a>&#160;&#160;»
</div>
<br />
<script type="text/javascript" src="_static/js/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript" src="_static/js/jquery-1.11.4-ui.min.js"></script>
<script type="text/javascript" src="_static/js/forge-0.7.0.min.js"></script>
<script type="text/javascript" src="../../../JSAV/lib/jquery.transit.js"></script>
<script type="text/javascript" src="../../../JSAV/lib/raphael.js"></script>
<script type="text/javascript" src="../../../JSAV/build/JSAV-min.js"></script>
<script type="text/javascript" src="_static/js/config.js"></script>
<script type="text/javascript" src="../../../lib/odsaUtils-min.js"></script>
<script type="text/javascript" src="../../../lib/odsaMOD-min.js"></script>
<script type="text/javascript" src="_static/js/d3-4.13.0.min.js"></script>
<script type="text/javascript" src="_static/js/d3-selection-multi.v1.min.js"></script>
<script type="text/javascript" src="../../../lib/dataStructures.js"></script>
<div class="container">
<script>ODSA.SETTINGS.DISP_MOD_COMP = true;ODSA.SETTINGS.MODULE_NAME = "AppBroadcast";ODSA.SETTINGS.MODULE_LONG_NAME = "Application-Layer Broadcasting: DHCP";ODSA.SETTINGS.MODULE_CHAPTER = "Networked Concurrency"; ODSA.SETTINGS.BUILD_DATE = "2021-06-01 15:31:50"; ODSA.SETTINGS.BUILD_CMAP = false;JSAV_OPTIONS['lang']='en';JSAV_EXERCISE_OPTIONS['code']='java';</script><div class="section" id="application-layer-broadcasting-dhcp">
<h1>4.7. Application-Layer Broadcasting: DHCP<a class="headerlink" href="AppBroadcast.html#application-layer-broadcasting-dhcp" title="Permalink to this headline"></a></h1>
<p>DNS provides a mechanism that clients can use to determine the IP address for a server based on a
human-readable domain name. In addition, server processes for common protocols listen for incoming
requests on well-known ports. The client can use the address and port number to call <code class="docutils literal notranslate"><span class="pre">connect()</span></code>
to establish a TCP connection for an HTTP request; for UDP services like DNS, the client uses the
address and port number when it calls <code class="docutils literal notranslate"><span class="pre">sendto()</span></code> to deliver the datagram. Thus, in both cases,
there are clear mechanisms for how the client determines the IP address and port number for the
server. This raises the question of how the server determines the corresponding information to send
the message back to the client.</p>
<p>One part of the answer to this question is that the TCP and UDP services provide this information
along with the request. As we will note in the next chapter, transport-layer protocols attach a
header to application-layer data containing the IP address and port numbers for both the sender and
the receiver. However, this answer is not fully satisfying, because it does not explain how the
clients IP address is set. (Explaining the port number is easy: For ephemeral ports, the OS picks a
random 16-bit number, typically above the value 4096.)</p>
<p>IP addresses can be either <a class="reference internal" href="Glossary.html#term-static-ip-address"><span class="xref std std-term">static</span></a> or <a class="reference internal" href="Glossary.html#term-dynamic-ip-address"><span class="xref std std-term">dynamic</span></a>. With a static IP address, the ISP determines a constant value that gets persistently
associated for a particular device; the device is configured so that it uses the same IP address
every time it boots up. Static IP addresses are commonly used for servers; this practice reduces
strain on the DNS, which would have to be updated every time the IP address for a server changed.
For end-user client devices, such as laptops, tablets, mobile phones, or Internet-connected <em>smart
home</em> devices, IP addresses are normally determined by the <a class="reference internal" href="Glossary.html#term-dynamic-host-configuration-protocol"><span class="xref std std-term">Dynamic Host Configuration
Protocol</span></a> (DHCP), a protocol that assigns IP addresses dynamically when the device connects to a
network. Note that this protocol is used in both wireless and wired networks, as DHCP will also run
when a computer is connected via an Ethernet cable.</p>
<div class="section" id="dhcp-overview">
<h2>4.7.1. DHCP Overview<a class="headerlink" href="AppBroadcast.html#dhcp-overview" title="Permalink to this headline"></a></h2>
<p>The specification for DHCP is defined in RFC 2131. The full protocol is significantly more complex
than either HTTP or DNS, because DHCP requires multiple steps rather than the basic request-response
structure. DHCP message exchanges can include negotiation back and forth between the client and
server based on the hardware and software requirements of each. Additionally, clients can abort the
request before the protocol completes, and the server would need to recognize when this happens and
close the connection to free up resources. Implementing the full specification requires building
state machines for both the client and server. In this section, though, we limit the discussion to
the most basic type of (successful) exchange because it illustrates a new socket programming
technique not discussed previously: <a class="reference internal" href="Glossary.html#term-broadcast"><span class="xref std std-term">broadcasting</span></a>.</p>
<div class="figure mb-2 align-right" id="id1" style="width: 45%">
<span id="dhcpbroadcast"></span><a class="reference internal image-reference" href="_images/CSF-Images.4.13.png"><img class="p-3 mb-2 align-center border border-dark rounded-lg" alt="Sequence of DHCP messages across a network" src="_images/CSF-Images.4.13.png" style="width: 95%;" /></a>
<p class="caption align-center px-3"><span class="caption-text"> Figure 4.7.1: Sequence of DHCP messages across a network</span></p>
</div>
<p><a href="AppBroadcast.html#dhcpbroadcast">Figure 4.7.1</a> illustrates the sequence of messages across a network for a DHCP
request. To initiate a DHCP request, a new client (such as a laptop) uses UDP to broadcast a <code class="docutils literal notranslate"><span class="pre">DHCP</span>
<span class="pre">discover</span></code> message, which declares that the sender is trying to find a DHCP server. In other words,
the client sends a message using a reserved IP address that indicates the client does not know the
destination. If the client is connected to a router that is running a DHCP server, the router would
accept the message and would not forward it. However, if there is no intervening router (e.g., the
client is connected via an Ethernet cable), then the message is sent to all hosts on the local
network. Most devices on the network are not running DHCP servers, so they have no process listening
at the well-known DHCP port number (67). For instance, a connected smart TV or network-accessible
storage (NAS) hard drive would not be listening for incoming DHCP requests. For these devices, the
OS simply ignores the message.</p>
<p>When the broadcast message is received by a DHCP server, the server replies by broadcasting a <code class="docutils literal notranslate"><span class="pre">DHCP</span>
<span class="pre">offer</span></code> that informs the client of the servers IP address, as well as proposing an IP address for
the client to use. If there are multiple DHCP servers running on the network, then any that receives
the <code class="docutils literal notranslate"><span class="pre">DHCP</span> <span class="pre">discover</span></code> message will respond with a <code class="docutils literal notranslate"><span class="pre">DHCP</span> <span class="pre">offer</span></code>. The client accepts the offer by
sending a <code class="docutils literal notranslate"><span class="pre">DHCP</span> <span class="pre">request</span></code>. Although this message is broadcast, the body of the request contains
information to designate which DHCP servers offer is being accepted. That server confirms the
configuration to all devices by broadcasting a final <code class="docutils literal notranslate"><span class="pre">DHCP</span> <span class="pre">ACK</span></code> (acknowledgement) that declares
the new client has successfully been assigned to that particular IP address.</p>
</div>
<div class="section" id="dhcp-protocol-messages">
<h2>4.7.2. DHCP Protocol Messages<a class="headerlink" href="AppBroadcast.html#dhcp-protocol-messages" title="Permalink to this headline"></a></h2>
<center>
<div class="col-md-6">
<table class="table table-bordered">
<thead class="jmu-dark-purple-bg text-light">
<tr>
<th class="p-0 center" style="width: 25%">0-7</th>
<th class="p-0 center" style="width: 25%">8-15</th>
<th class="p-0 center" style="width: 25%">16-23</th>
<th class="p-0 center" style="width: 25%">24-31</th>
</tr>
</thead>
<tbody>
<tr>
<td class="py-0 center"><code>op</code></td>
<td class="py-0 center"><code>htype</code></td>
<td class="py-0 center"><code>hlen</code></td>
<td class="py-0 center"><code>hops</code></td>
</tr>
<tr> <td class="py-0 center" colspan="4"><code>xid</code></td> </tr>
<tr>
<td class="py-0 center" colspan="2"><code>secs</code></td>
<td class="py-0 center" colspan="2"><code>flags</code></td>
</tr>
<tr> <td class="py-0 center" colspan="4"><code>ciaddr</code></td> </tr>
<tr> <td class="py-0 center" colspan="4"><code>yiaddr</code></td> </tr>
<tr> <td class="py-0 center" colspan="4"><code>siaddr</code></td> </tr>
<tr> <td class="py-0 center" colspan="4"><code>giaddr</code></td> </tr>
<tr> <td class="py-0 center" colspan="4"><code>chaddr (16 bytes)</code></td> </tr>
<tr> <td class="py-0 center" colspan="4"><code>sname (64 bytes)</code></td> </tr>
<tr> <td class="py-0 center" colspan="4"><code>file (128 bytes)</code></td> </tr>
<tr> <td class="py-0 center" colspan="4"><code>options (variable)</code></td> </tr>
</tr>
</tbody>
</table>
</div>
<p>
Table 4.10: Structure of a DHCP message
</p>
</center><p>RFC 2131 defines the core structure of DHCP messages, which is shown in <a class="reference external" href="AppBroadcast.html#tbl4-10">Table 4.10</a>. In
this illustration, each row of the table is 32 bits (four bytes) wide, and some fields would require
multiple rows, as they are larger than four bytes in size. While this structure shows the relative
ordering of the fields, the exact structure depends on the type of message. Depending on the type,
some fields may be required, others are optional, and still more are not allowed. RFC 2132 specifies
the allowable options.</p>
<p>For the four basic messages shown in <a href="AppBroadcast.html#dhcpbroadcast">Figure 4.7.1</a>, the important fields to consider
are <code class="docutils literal notranslate"><span class="pre">op</span></code>, <code class="docutils literal notranslate"><span class="pre">xid</span></code>, <code class="docutils literal notranslate"><span class="pre">yiaddr</span></code>, and <code class="docutils literal notranslate"><span class="pre">siaddr</span></code>. The <code class="docutils literal notranslate"><span class="pre">op</span></code> field can be set to either
<code class="docutils literal notranslate"><span class="pre">BOOTREQUEST</span></code> (1) or <code class="docutils literal notranslate"><span class="pre">BOOTREPLY</span></code> (2), indicating if the message is coming from the client or the
server. As in DNS, the <code class="docutils literal notranslate"><span class="pre">xid</span></code> is a random integer to denote the transaction ID, connecting replies
with the specific requests. The <code class="docutils literal notranslate"><span class="pre">yiaddr</span></code> is used to indicate <em>your</em> (the clients) IP address,
while siaddr is the DHCP servers address. The other fields, described in the RFC, are beyond the
scope of this book. <a class="reference external" href="AppBroadcast.html#tbl4-11">Table 4.11</a> shows the values of these fields for a sample DHCP
request. All messages are sent to the destination IP address 255.255.255.255, which is the reserved
value that indicates a broadcast message. The client uses 0.0.0.0 as its source address for the UDP
messages, indicating the sending host has no valid address, while the DHCP server can use its own address.</p>
<p>The client distinguishes itself from other new clients by picking a random value to use as the
<code class="docutils literal notranslate"><span class="pre">xid</span></code>, which is 42 for the <code class="docutils literal notranslate"><span class="pre">DHCP</span> <span class="pre">discover</span></code> message in this case; after the server replies with
the same <code class="docutils literal notranslate"><span class="pre">xid</span></code> value, the client and the server repeat the same value again in the later messages. A
<code class="docutils literal notranslate"><span class="pre">DHCP</span> <span class="pre">discover</span></code> message from another new client might have 587 for its <code class="docutils literal notranslate"><span class="pre">xid</span></code>. By receiving a
broadcast message with <code class="docutils literal notranslate"><span class="pre">xid</span></code> 42 from the server, the client that started with 42 has
reasonable assurance that it is the intended recipient.</p>
<center>
<table class="table table-bordered">
<thead class="jmu-dark-purple-bg text-light">
<tr>
<th class="py-0 center">Message type</th>
<th class="py-0 center">UDP addressing</th>
<th class="py-0 center">DHCP contents</th>
</tr>
</thead>
<tbody>
<tr>
<td class="py-0"><code>DHCP discover</code></td>
<td class="py-0"><code>SRC: 0.0.0.0:68<br />DEST: 255.255.255.255:67</code></td>
<td class="py-0"><code>op: BOOTREQUEST<br />xid: 42<br />yiaddr: 0.0.0.0</code></td>
</tr>
<tr>
<td class="py-0"><code>DHCP offer</code></td>
<td class="py-0"><code>SRC: 192.168.1.1:67<br />DEST: 255.255.255.255:68</code></td>
<td class="py-0"><code>op: BOOTREPLY<br />xid: 42<br />yiaddr: 192.168.1.7<br />siaddr: 192.168.1.1<br />lease time: 86400</code></td>
</tr>
<tr>
<td class="py-0"><code>DHCP request</code></td>
<td class="py-0"><code>SRC: 0.0.0.0:68<br />DEST: 255.255.255.255:67</code></td>
<td class="py-0"><code>op: BOOTREQUEST<br />xid: 42<br />ciaddr: 192.168.1.7</code></td>
</tr>
<tr>
<td class="py-0"><code>DHCP ACK</code></td>
<td class="py-0"><code>SRC: 192.168.1.1:67<br />DEST: 255.255.255.255:68</code></td>
<td class="py-0"><code>op: BOOTREPLY<br />xid: 42<br />yiaddr: 192.168.1.7<br />siaddr: 192.168.1.1<br />lease time: 86400</code></td>
</tr>
</tbody>
</table>
<p>
Table: 4.11: Structure of DHCP messages to set up an IP address
</p>
</center><p>The other fields in the DHCP message establish the new clients IP configuration. When the server
sends the <code class="docutils literal notranslate"><span class="pre">DHCP</span> <span class="pre">offer</span></code>, the <code class="docutils literal notranslate"><span class="pre">yiaddr</span></code> field contains a proposed value for the clients address.
The client could reject the address, but here we assume that the offer is accepted. The client
indicates that it accepts the offer by using the same value in its <code class="docutils literal notranslate"><span class="pre">DHCP</span> <span class="pre">request</span></code>, and the server
confirms the acceptance in the <code class="docutils literal notranslate"><span class="pre">DHCP</span> <span class="pre">ACK</span></code>. In addition, these messages establish that the client
knows the IP address of the DHCP server (<code class="docutils literal notranslate"><span class="pre">siaddr</span></code>), along with the duration of the
<em>lease</em>—the time during which the client owns this IP address. In this case, the client will
have a lease on the address 192.168.1.7 for a maximum of 86,400 seconds (24 hours). When the lease
expires, the client would contact the server to renew the lease. At that point, the client would not
need to repeat the full protocol; since the client knows the IP address of the server, it does not
need to begin back at the <code class="docutils literal notranslate"><span class="pre">DHCP</span> <span class="pre">discover</span></code> stage.</p>
<div
id="BroadcastSumm"
class="embedContainer"
data-exer-name="BroadcastSumm"
data-long-name="Socket broadcasting questions"
data-short-name="BroadcastSumm"
data-frame-src="../../../Exercises/Sockets/BroadcastSumm.html?selfLoggingEnabled=false&amp;localMode=true&amp;module=AppBroadcast&amp;JXOP-debug=true&amp;JOP-lang=en&amp;JXOP-code=java"
data-frame-width="950"
data-frame-height="550"
data-external="false"
data-points="1.0"
data-required="True"
data-showhide="show"
data-threshold="4"
data-type="ka"
data-exer-id="">
<div class="center">
<div id="BroadcastSumm_iframe"></div>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="mt-4 container center">
«&#160;&#160;<a id="prevmod1" href="UDPSockets.html">4.6. UDP Socket Programming: DNS</a>
&#160;&#160;::&#160;&#160;
<a class="uplink" href="index.html">Contents</a>
&#160;&#160;::&#160;&#160;
<a id="nextmod1" href="Extended4CGI.html">4.8. Extended Example: CGI Web Server</a>&#160;&#160;»
</div>
</div>
<br />
<div class="row jmu-dark-purple-bg">
<div class="col-md-12">
<center>
<a id="contact_us" class="btn button-link-no-blue jmu-gold" rel="nofollow" href="mailto:webmaster@opencsf.org" role="button">Contact Us</a>
<a id="license" class="btn button-link-no-blue jmu-gold" rel="nofollow" href="https://w3.cs.jmu.edu/kirkpams/OpenCSF/lib/license.html" target="_blank">License</a>
</center>
</div>
</div>
<script src="_static/js/popper.js-1.14.7-min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="_static/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>