Linux Network Programming API process [reprinted], linux Network Programming api
Original article: http://blog.chinaunix.net/uid-23069658-id-3300460.html Linux network programming data sending and receiving API Process Analysis as long as the data in the protocol stack flow line and context clearly, the implementation of the protocol stack part, understanding it is much easier. In the data receiving process in the network programming chapter, we mainly introduced read (), recv (), recvfrom (), and recvmsg, today, let's take a look at the differences between these API functions.Receive dataThe process of receiving data is divided into two phases: BOTTOM-HALF and TOP-HALF. BOTTOM-HALF: When a packet is received from the NIC driver, it enters the BOTTOM-HALF stage. Here, the specific protocol type, such as IP address, must be determined based on the Type field in the Ethernet frame header, or ARP or RARP. The IP packet processing function is usually delivered to the ip_recv () function for processing, and the data enters the network layer. The specific process is as follows: if the packet is sent to the local machine, the ip_local_deliver () function is generally called, if the local host needs to be forwarded and the local host has enabled the forwarding function, the ip_forward () function is called. Here we can see the figure of Netfilter. We haven't seen it for a long time, but it's still kind. You can refer to this picture to understand the relationship between Netfilter and protocol stack. BOTTOM-HALF finally fills the received skb in the receiving queue of the socket, see. TOP-HALF: the BOTTOM-HALF stage. The main task of this stage is to extract a skb from the receiving queue and transmit it to the user space, as shown below, these functions are eventually integrated into one: __sock_recvmsg ().Data TransmissionSimilarly, data transmission is divided into two stages. In contrast to the receiving situation, there must also be a sending queue for sending data. That's right. The APIS we introduced when sending data packets include write (), send (), sendto (), and sendmsg. TOP-HALF is as follows: BOTTOM-HALF is as follows: after such an exploration, we have a better understanding of the data sending and receiving APIs than others. As to how the callback and call relationships between different functions are established, we will further discuss them in the protocol stack analysis chapter. Finally, let's take a look at the family.