# Protocol_Stack2022 **Repository Path**: bessiechen2022/protocol_-stack2022 ## Basic Information - **Project Name**: Protocol_Stack2022 - **Description**: This project aims to reproduce a simple network protocol stack, including ARP protocol, IP protocol, ICMP protocol, UDP protocol and time server, TCP protocol, and HTTP server components. - **Primary Language**: C - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2022-06-30 - **Last Updated**: 2023-12-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # TCP/IP Protocol Stack This project aims to reproduce a simple network protocol stack, including Ethernet packet transmission and reception, ARP protocol, IP protocol, ICMP protocol, UDP protocol and time server, TCP protocol, and HTTP server components. The project is divided into the following parts: ### Ethernet Packet Transmission and Reception Implementation By defining the packet structure, encapsulating Ethernet drivers, and handling Ethernet input and output, the transmission and reception of Ethernet packets are realized. #### Virtual machine ping protocol stack ![输入图片说明](src/img/1.%20%E8%99%9A%E6%8B%9F%E6%9C%BA%20ping%20%E5%8D%8F%E8%AE%AE%E6%A0%88.png) #### Debugging our program's network protocol stack ![输入图片说明](src/img/2.%20%E8%B0%83%E8%AF%95%E6%88%91%E4%BB%AC%E7%A8%8B%E5%BA%8F%E7%9A%84%E7%BD%91%E7%BB%9C%E5%8D%8F%E8%AE%AE%E6%A0%88.png) ### ARP Protocol Implementation Initialization of ARP, generation of non-return ARP, processing ARP input, and re-requesting ARP in case of timeout. #### Virtual machine ARP table entry update ![输入图片说明](src/img/3.%20%E8%99%9A%E6%8B%9F%E6%9C%BAarp%E8%A1%A8%E9%A1%B9%E6%9B%B4%E6%96%B0.png) ### IP Protocol Implementation Implemented input and output processing functions of the IP layer. #### Protocol stack successfully handle IP packets from virtual machines ![输入图片说明](src/img/4.%20%E5%8D%8F%E8%AE%AE%E6%A0%88%E8%83%BD%E5%90%A6%E6%88%90%E5%8A%9F%22%E5%A4%84%E7%90%86%E6%9D%A5%E8%87%AA%E8%99%9A%E6%8B%9F%E6%9C%BA%E7%9A%84ip%E5%8C%85%22.png) ![输入图片说明](src/img/4.%20%E5%8D%8F%E8%AE%AE%E6%A0%88%E8%83%BD%E5%90%A6%E6%88%90%E5%8A%9F%22%E5%A4%84%E7%90%86%E6%9D%A5%E8%87%AA%E8%99%9A%E6%8B%9F%E6%9C%BA%E7%9A%84ip%E5%8C%85%22%E5%8D%8F%E8%AE%AE%E6%A0%88%E8%83%BD%E5%90%A6%E6%88%90%E5%8A%9F%22%E5%A4%84%E7%90%86%E6%9D%A5%E8%87%AA%E8%99%9A%E6%8B%9F%E6%9C%BA%E7%9A%84ip%E5%8C%85%222.png) ### ICMP Protocol Implementation Implemented response to ping requests and response to destination unreachable messages. #### Protocol stack successfully replies ICMP packet to virtual machine, and checksum calculation is correct ![输入图片说明](src/img/5.%20%E5%8D%8F%E8%AE%AE%E6%A0%88%E6%88%90%E5%8A%9F%E5%9B%9E%E5%A4%8Dicmp%E5%8C%85%E7%BB%99%E8%99%9A%E6%8B%9F%E6%9C%BA,%20%E5%B9%B6%E4%B8%94checksum%E8%AE%A1%E7%AE%97%E6%AD%A3%E7%A1%AE.png) #### Protocol stack successfully receives ICMP packet sent by virtual machine and successfully parses it ![输入图片说明](src/img/5.%20%E5%8D%8F%E8%AE%AE%E6%A0%88%E6%88%90%E5%8A%9F%E6%8E%A5%E6%94%B6%E8%99%9A%E6%8B%9F%E6%9C%BA%E4%BC%A0%E6%9D%A5%E7%9A%84icmp%E5%8C%85%E5%B9%B6%E6%88%90%E5%8A%9F%E8%A7%A3%E6%9E%90.png) #### Remote host forces connection to close ![输入图片说明](src/img/6.%20%E8%BF%9C%E7%A8%8B%E4%B8%BB%E6%9C%BA%E5%BC%BA%E8%BF%AB%E5%85%B3%E9%97%AD%E8%BF%9E%E6%8E%A5.png) ![输入图片说明](src/img/6.%20%E8%BF%9C%E7%A8%8B%E4%B8%BB%E6%9C%BA%E5%BC%BA%E8%BF%AB%E5%85%B3%E9%97%AD%E8%BF%9E%E6%8E%A52.png) ### UDP Protocol and Time Server Implementation By establishing the UDP control structure and adding basic UDP operation interfaces, the time server's reception processing, UDP input processing, and UDP output processing are implemented. #### Protocol stack's handler can successfully send UDP reply packet ![输入图片说明](src/img/7.%20%E5%8D%8F%E8%AE%AE%E6%A0%88%E7%9A%84handler%E5%8F%AF%E4%BB%A5%E6%88%90%E5%8A%9F%E5%8F%91%E9%80%81UDP%E5%9B%9E%E5%A4%8D%E5%8C%85.png) ![输入图片说明](src/img/7.%20%E5%8D%8F%E8%AE%AE%E6%A0%88%E7%9A%84handler%E5%8F%AF%E4%BB%A5%E6%88%90%E5%8A%9F%E5%8F%91%E9%80%81UDP%E5%9B%9E%E5%A4%8D%E5%8C%852.png) #### Protocol stack can successfully read UDP packets sent by virtual machine ![输入图片说明](src/img/7.%20%E5%8D%8F%E8%AE%AE%E6%A0%88%E8%83%BD%E5%A4%9F%E6%88%90%E5%8A%9F%E8%AF%BB%E5%8F%96%E8%99%9A%E6%8B%9F%E6%9C%BA%E5%8F%91%E6%9D%A5%E7%9A%84UDP%E5%8C%85.png) #### Observing the situation after the UDP packet is sent from the virtual machine if the network protocol stack is closed ![输入图片说明](src/img/7.%20%E5%A6%82%E6%9E%9C%E7%BD%91%E7%BB%9C%E5%8D%8F%E8%AE%AE%E6%A0%88%E5%A4%84%E4%BA%8E%E5%85%B3%E9%97%AD%E7%8A%B6%E6%80%81,%20%E8%A7%82%E5%AF%9FUDP%E5%8C%85%E4%BB%8E%E8%99%9A%E6%8B%9F%E6%9C%BA%E5%8F%91%E9%80%81%E5%90%8E%E7%9A%84%E6%83%85%E5%86%B5.png) #### Successfully receive UDP packet ![输入图片说明](src/img/7.%20%E6%88%90%E5%8A%9F%E6%8E%A5%E6%94%B6UDP%E5%8C%85.png) ### TCP Protocol Implementation Includes establishing the TCP control structure, adding basic TCP operation interfaces, implementing TCP's three-way handshake, four-way wave, data transmission, and data reception functions. #### 3-way handshake and 4-way handshake ![输入图片说明](src/img/8.%203%E6%AC%A1%E6%8F%A1%E6%89%8B+4%E6%AC%A1%E6%8C%A5%E6%89%8B.png) #### Read MSS during the three-way handshake ![输入图片说明](src/img/8.%20MSS%E7%9A%84%E5%AD%98%E5%82%A8%E6%83%85%E5%86%B5.%20%E6%88%91%E4%BB%AC%E5%9C%A8%E4%B8%89%E6%AC%A1%E6%8F%A1%E6%89%8B%E7%9A%84%E6%97%B6%E5%80%99%E5%B0%B1%E8%A6%81%E5%B0%86%E5%AE%83%E8%AF%BB%E5%8F%96%E5%87%BA%E6%9D%A5.png) #### Successfully receive TCP packet ![输入图片说明](src/img/8.%20%E6%88%90%E5%8A%9F%E6%8E%A5%E6%94%B6TCP%E5%8C%85.png) #### Passive close ![输入图片说明](src/img/8.%20%E8%A2%AB%E5%8A%A8%E5%85%B3%E9%97%AD%E6%88%90%E5%8A%9F.png) #### Protocol stack can implement 3-way handshake, 4-way handshake, actively send and receive data and return it unchanged ![输入图片说明](src/img/9.%20%E5%8D%8F%E8%AE%AE%E6%A0%88%E8%83%BD%E5%A4%9F%E5%AE%9E%E7%8E%B03%E6%AC%A1%E6%8F%A1%E6%89%8B+4%E6%AC%A1%E6%8C%A5%E6%89%8B+%E4%B8%BB%E5%8A%A8%E5%8F%91%E9%80%81%E6%95%B0%E6%8D%AE+%E6%8E%A5%E6%94%B6%E6%95%B0%E6%8D%AE%E5%B9%B6%E5%8E%9F%E6%A0%B7%E8%BF%94%E5%9B%9E.png) ### HTTP Server Implementation Built a simple front-end page, implementing HTTP connection, webpage return, and 404 error return functions. #### After opening the protocol stack, it is found that the 3-way handshake is successful, and it can receive the 404 request from the browser and respond accordingly ![输入图片说明](src/img/10.%20%E5%BC%80%E5%90%AF%E5%8D%8F%E8%AE%AE%E6%A0%88%E4%B9%8B%E5%90%8E,%20%E5%8F%91%E7%8E%B0%E6%88%90%E5%8A%9F3%E6%AC%A1%E6%8F%A1%E6%89%8B,%20%E5%B9%B6%E4%B8%94%E5%8F%AF%E4%BB%A5%E6%8E%A5%E6%94%B6%E6%B5%8F%E8%A7%88%E5%99%A8%E4%BC%A0%E6%9D%A5%E7%9A%84404%E8%AF%B7%E6%B1%82%E5%B9%B6%E7%9B%B8%E5%BA%94.png) Although this network protocol stack is small, it basically covers the functionality from low-level Ethernet packet transmission and reception to high-level HTTP servers. This provides a foundation for further research on network communication principles and the development of network applications.