![](https://csdnimg.cn/release/download_crawler_static/86345502/bg4.jpg)
18. What does the IP Input do in the 4.4BSD-Lite distribution?P15
IP input is asynchronous and is scheduled to run by a software interrupt. The software interrupt is set by the
interface layer when it receives an IP datagram on one of the system's interfaces. When the IP input routine
executes it loops, processing each IP datagram on its input queue and returning when the entire queue has been
processed.
The IP input routine processes each IP datagram that it receives. It verifies the IP header checksum, processes any
IP options, verifies that the datagram was delivered to the right host (by comparing the destination IP address of
the datagram with the host's IP addresses), and forwards the datagram if the system was configured as a router
and the datagram is destined for some other IP address. If the IP datagram has reached its final destination, the
protocol field in the IP header specifies which protocol's input routine is called: ICMP, IGMP, TCP, or UDP. In our
example, the UDP input routine is called to process the UDP datagram.
19. What does the UDP input do in the 4.4BSD-Lite distribution?p16
The UDP input routine verifies the fields in the UDP header (the length and optional checksum) and then
determines whether or not a process should receive the datagram.
20. In the example program we never specify the local port number for the application. We'll see in Exercise 23.3 that a
side effect of writing the first UDP datagram to a socket that has not yet bound a local port number is the automatic
assignment by the kernel of a local port number (termed an ephemeral port) to that socket. That's how the inp_lport
member of the PCB for our socket gets set to some nonzero value. Please find the corresponding codes in
in_pcbconnect function, and in_pcbbind function. [可以学完 23 章再做]
P593 Figure 22.28. in_pcbconnect function:
verify that socket pair is unique. Line
234-238: Implicit bind and assignment of
ephemeral port.
P588 Figure 22.23. in_pcbbind function:
choose an ephemeral port Line 113-121
21. What does the example process input
do?P17
Our process has been asleep in the
kernel, blocked in its call to recvfrom, and
the process now wakes up. The 26 bytes of
data appended to the socket's receive
queue by the UDP layer (the received
datagram) are copied by the kernel from
the mbuf into our program's buffer.
Notice that our program sets the fifth
and sixth arguments to recvfrom to null pointers, telling the system call that we're not interested in receiving the
sender's IP address and UDP port number. This causes the recvfrom system call to skip the first mbuf in the chain
(Figure 1.11), returning only the 26 bytes of data in the second mbuf. The kernel's recvfrom code then releases the two
mbufs in Figure 1.11 and returns them to its pool of free mbufs.
The program reads the datagram(数据包) that the server sends back by calling recvfrom. Our program overwrites the
carriage return with a null byte and calls printf to output the result.