A data packet sending method, device, terminal and medium
By saving the correspondence between the network port and the destination IP in the Android system terminal, the forwarding of data packets between different networks is realized, and the problem that the terminal does not support multi-network interoperability is solved, ensuring the successful transmission of data packets.
Patent Information
- Application Number
- CN202210670631.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-14
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2042-06-14
AI Technical Summary
In the prior art, terminals using the Android system do not support multi-network interoperability, resulting in failure of sending if the terminal does not connect to the second device through the network after receiving the data packets sent by the first device through the certain network.
By saving the correspondence between the network port of each network and the destination IP in the terminal, after receiving the data packet, the target network port is searched according to the destination IP carried in the data packet, and sending a data packet to the second device corresponding to the destination IP through the network port.
It realizes data packet forwarding between different networks by terminals, solves the problem that terminals do not support multi-network interoperability, and ensures that data packets can be successfully delivered to the destination device.
Smart Images

Figure CN115175266B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of network communication technology, and in particular to a method, device, terminal and medium for sending a data packet. Background Art
[0002] With the development of technology, more and more terminals are put into production and life. Among them, most terminals use the Android system, and the terminals can use a variety of networks, such as Wi-Fi, Ethernet, mobile networks, etc.
[0003] Among them, in production and life, due to the limitations of application scenarios, terminals using the Android system have the function of forwarding data packets, that is, the terminal needs to forward the data packets sent by the first device to the second device. However, due to the limitations of the Android system, after the terminal receives the data packet sent by the first device through any network, the terminal can only forward the data packet to the second device through the network. If the terminal is not connected to the second device through the network, the transmission fails.
[0004] For example, a terminal is connected to an image acquisition device via Ethernet, and is also connected to a router via Wi-Fi, and a laptop is also connected to the router. In this way, the terminal is actually connected to two independent networks. The image acquisition device sends the captured image to the terminal via Ethernet. After the terminal receives the image, it sends the image to the laptop via the network port or default port corresponding to the Ethernet. However, since the laptop is connected to the terminal via Wi-Fi, this causes the sending to fail. In other words, in the prior art, terminals using the Android system do not support multi-network intercommunication. Summary of the invention
[0005] The present application provides a data packet sending method, device, terminal and medium, which are used to solve the problem in the prior art that terminals using the Android system do not support multi-network intercommunication.
[0006] In a first aspect, an embodiment of the present application provides a method for sending a data packet, which is applied to a terminal, and the method includes:
[0007] Receive a data packet sent by the first device through the target network, and obtain a destination IP address carried in the data packet;
[0008] According to the saved correspondence between the network port of each network and the destination IP, find the target network port corresponding to the destination IP;
[0009] According to the target network port, the data packet is sent to the second device corresponding to the destination IP.
[0010] In a second aspect, an embodiment of the present application further provides a data packet sending device, which is applied to a terminal, and the device includes:
[0011] A receiving module, configured to receive a data packet sent by the first device through a target network;
[0012] The processing module is used to obtain the destination IP carried in the data packet; and find the target network port corresponding to the destination IP according to the stored correspondence between the network port of each network and the destination IP;
[0013] The sending module is used to send the data packet to the second device corresponding to the destination IP according to the target network port.
[0014] In a third aspect, an embodiment of the present application further provides a terminal, the terminal comprising:
[0015] Display, processor and memory;
[0016] The display is used to display the screen display area;
[0017] The memory is used to store the processor executable instructions;
[0018] The processor is configured to execute the instructions to implement the data packet sending method as described in any one of the above.
[0019] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of any of the above-described methods for sending data packets.
[0020] In an embodiment of the present application, a data packet sent by a first device through a target network is received, a destination IP carried in the data packet is obtained, and a target network port corresponding to the destination IP is searched according to the stored correspondence between the network port of each network and the destination IP, and the data packet is sent to a second device corresponding to the destination IP according to the target network port. That is, in an embodiment of the present application, a correspondence between the network port of each network and the destination IP is stored in the terminal. After the terminal receives a data packet sent by the first device through the target network, according to the destination IP carried in the data packet, a target network port corresponding to the destination IP is searched in the correspondence, and the data packet is sent to a second device corresponding to the destination IP through the target network port. Therefore, even if the first device and the second device are located in two different networks, the terminal can forward the data packet, thereby realizing multi-network intercommunication of the terminal. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solution of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0022] Figure 1 A schematic diagram of the structure of a terminal 100 is shown;
[0023] Figure 2 is a software structure block diagram of a terminal 100 according to an embodiment of the present application;
[0024] Figure 3 A schematic diagram of a data packet sending process provided in an embodiment of the present application;
[0025] Figure 4 An application scenario of the terminal provided in the embodiment of the present application;
[0026] Figure 5 A schematic diagram of a policy table of a Linux system provided in an embodiment of the present application;
[0027] Figure 6 A schematic diagram of the main routing table of the Linux system provided in the embodiment of the present application;
[0028] Figure 7 A schematic diagram of a policy table in a terminal provided in an embodiment of the present application;
[0029] Figure 8 A schematic diagram of a terminal of a routing table named 1029 in a terminal provided in an embodiment of the present application;
[0030] Fig. 9 A schematic diagram of a legacy_system routing table with other routing rules added to each routing table provided in an embodiment of the present application;
[0031] Fig.10 A schematic diagram of a specific process of forwarding a data packet provided in an embodiment of the present application;
[0032] Fig.11 A schematic diagram of the structure of a video recording device provided in an embodiment of the present application;
[0033] Fig.12 Another structural schematic diagram of a terminal provided in an embodiment of the present application. DETAILED DESCRIPTION
[0034] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.
[0035] Figure 1 1 shows a schematic diagram of the structure of a terminal 100. It should be understood that Figure 1 The terminal 100 shown is only an example and the terminal 100 may have more Figure 1 The more or less components shown in the figure can be combined with two or more components, or can have different component configurations. The various components shown in the figure can be implemented in hardware, software, or a combination of hardware and software including one or more signal processing and / or application specific integrated circuits.
[0036] Figure 1 FIG. 1 is a block diagram showing a hardware configuration of the terminal 100 according to an exemplary embodiment. Figure 1 As shown, the terminal 100 includes: a radio frequency (RF) circuit 110, a memory 120, a display unit 130, a camera 140, a sensor 150, an audio circuit 160, a wireless fidelity (Wi-Fi) module 170, a processor 180, a Bluetooth module 181, and a power supply 190 and other components.
[0037] The RF circuit 110 can be used to receive and send signals during the process of sending and receiving information or making calls. It can receive downlink data from the base station and hand it over to the processor 180 for processing; it can send uplink data to the base station. Generally, the RF circuit includes but is not limited to antennas, at least one amplifier, a transceiver, a coupler, a low noise amplifier, a duplexer and other devices.
[0038] The memory 120 can be used to store software programs and data. The processor 180 executes various functions and data processing of the terminal 100 by running the software programs or data stored in the memory 120. The memory 120 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage device. The memory 120 stores an operating system that enables the terminal 100 to run. In the present application, the memory 120 can store an operating system and various application programs, and can also store program codes for executing the power saving method of the terminal in the embodiment of the present application.
[0039] The display unit 130 may be used to receive input digital or character information and generate signal input related to user settings and function control of the terminal 100. Specifically, the display unit 130 may include a touch screen 131 disposed on the front of the terminal 100, which may collect user touch operations thereon or near the touch screen, such as clicking a button.
[0040] The display unit 130 can also be used to display information input by the user or information provided to the user and a graphical user interface (GUI) of various menus of the terminal 100. Specifically, the display unit 130 may include a display screen 132 disposed on the front of the terminal 100. The display screen 132 may be configured in the form of a liquid crystal display, a light emitting diode, etc. The display unit 130 may be used to display the screen display area of the terminal in the present application.
[0041] The touch screen 131 may be covered on the display screen 132, or the touch screen 131 and the display screen 132 may be integrated to realize the input and output functions of the terminal 100, and the integrated touch screen may be referred to as a touch display screen. In the present application, the display unit 130 may display the application and the corresponding operation steps.
[0042] The camera 140 can be used to capture still images or videos. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, which is then passed to the processor 180 for conversion into a digital image signal.
[0043] The terminal 100 may further include at least one sensor 150, such as an acceleration sensor 151, a distance sensor 152, a fingerprint sensor 153, and a temperature sensor 154. The terminal 100 may also be configured with other sensors such as a gyroscope, a barometer, a hygrometer, a thermometer, an infrared sensor, a light sensor, and a motion sensor.
[0044] The audio circuit 160, the speaker 161, and the microphone 162 can provide an audio interface between the user and the terminal 100. The audio circuit 160 can transmit the electrical signal converted from the received audio data to the speaker 161, which is converted into a sound signal for output. The terminal 100 can also be configured with a volume button for adjusting the volume of the sound signal, and can also be used to combine other buttons to adjust the closed area. On the other hand, the microphone 162 converts the collected sound signal into an electrical signal, which is received by the audio circuit 160 and converted into audio data, and then the audio data is output to the RF circuit 110 to be sent to, for example, another terminal, or the audio data is output to the memory 120 for further processing.
[0045] Wi-Fi is a short-range wireless transmission technology. The terminal 100 can help users send and receive emails, browse web pages, and access streaming media through the Wi-Fi module 170, which provides users with wireless broadband Internet access.
[0046] The processor 180 is the control center of the terminal 100. It uses various interfaces and lines to connect various parts of the entire terminal. It executes various functions of the terminal 100 and processes data by running or executing software programs stored in the memory 120 and calling data stored in the memory 120. In some embodiments, the processor 180 may include one or more processing units; the processor 180 may also integrate an application processor and a baseband processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the baseband processor mainly processes wireless communications. It is understandable that the above-mentioned baseband processor may not be integrated into the processor 180. In the present application, the processor 180 can run the operating system, application programs, user interface display and touch response, as well as the power saving method of the terminal in the embodiment of the present application. In addition, the processor 180 is coupled to the display unit 130.
[0047] The Bluetooth module 181 is used to exchange information with other Bluetooth devices having Bluetooth modules through the Bluetooth protocol. For example, the terminal 100 can establish a Bluetooth connection with a wearable electronic device (such as a smart watch) that also has a Bluetooth module through the Bluetooth module 181 to exchange data.
[0048] The terminal 100 also includes a power supply 190 (such as a battery) for supplying power to various components. The power supply can be logically connected to the processor 180 through a power management system, so that the power management system can manage functions such as charging, discharging, and power consumption. The terminal 100 can also be configured with a power button for turning on and off the terminal, as well as locking the screen and other functions.
[0049] Figure 2 It is a software structure block diagram of a terminal 100 according to an embodiment of the present application.
[0050] The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system can be divided into four layers, from top to bottom: the application layer, the application framework layer, the Android runtime and system library, and the kernel layer.
[0051] The application layer can include a series of application packages.
[0052] like Figure 2 As shown, the application package may include phone, MMS, Wi-Fi, WeChat, information, alarm clock, gallery, calendar, WLAN and other applications.
[0053] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions.
[0054] like Figure 2 As shown, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, and the like.
[0055] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc.
[0056] Content providers are used to store and retrieve data and make it accessible to applications. The data can include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, short messages, etc.
[0057] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a short message notification icon can include a view for displaying text and a view for displaying images.
[0058] The phone manager is used to provide communication functions of the terminal 100, such as management of call status (including connection, disconnection, etc.).
[0059] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, etc.
[0060] The notification manager enables applications to display notification information (such as the content of short messages) in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, the terminal vibrates, the indicator light flashes, etc.
[0061] Android Runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system.
[0062] The core library consists of two parts: one part is the function that needs to be called by the Java language, and the other part is the Android core library.
[0063] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0064] The system library may include multiple functional modules, such as surface manager, media library, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.
[0065] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple applications.
[0066] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0067] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0068] A 2D (animation mode) graphics engine is a drawing engine for 2D drawing.
[0069] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.
[0070] The terminal 100 in the embodiment of the present application may be an electronic device including but not limited to a smart phone, a tablet computer, a wearable electronic device (such as a smart watch), a laptop computer, etc.
[0071] Among them, in the embodiment of the present application, the above Figure 1 or Figure 2 The terminal shown can also receive a data packet sent by the first device through the target network, obtain the destination IP carried in the data packet, search for the target network port corresponding to the destination IP based on the saved correspondence between the network port of each network and the destination IP, and send the data packet to the second device corresponding to the destination IP based on the target network port.
[0072] In order to enable a terminal to achieve multi-network intercommunication when forwarding data packets, the embodiments of the present application provide a data packet sending method, device, terminal and medium.
[0073] Figure 3 A schematic diagram of a data packet sending process provided in an embodiment of the present application, the process includes:
[0074] S301: Receive a data packet sent by a first device through a target network, and obtain a destination IP address carried in the data packet.
[0075] The data packet sending method provided in the embodiment of the present application is applied to a terminal, which may be Figure 1 or Figure 2 Terminal shown.
[0076] The Android system in the terminal is an operating system based on the Linux system. In terms of network management, compared with the Linux system, the Android system has added some restrictions, which makes the terminal using the Android system not support multiple networks at the same time, and multiple networks cannot communicate with each other. However, in the fields of security, there are many application scenarios that require the use of multiple networks concurrently, for example, Figure 4 An application scenario of the terminal provided in the embodiment of the present application, such as the Figure 4 As shown in FIG. 1 , P50 is a terminal using the Android system. The terminal is connected to two image acquisition devices through two Ethernet cables. In addition, the terminal is also connected to a router through Wi-Fi, and a laptop is connected to the router. Figure 4 In the application scenario shown, the terminal has a need to forward data packets between different networks, that is, the terminal receives a data packet sent by any image acquisition device and needs to send the data packet to the notebook.
[0077] In the embodiment of the present application, the device that sends a data packet to the terminal is referred to as the first device, and the device that receives the data packet sent by the terminal is referred to as the second device. Specifically, the first device sends a data packet that needs to be forwarded by the terminal to the terminal, and the terminal receives the data packet, which carries a destination IP, wherein the destination IP is the IP address of the forwarding object of the terminal, that is, the IP address of the second device that ultimately receives the data packet. The terminal obtains the destination IP carried in the data packet, and sends the data packet to the second device based on the destination IP.
[0078] The first device sends data to the terminal via a certain network. In order to distinguish the network used by the first device to send the data packet to the terminal, in the embodiment of the present application, the network is referred to as the target network. The target network can be Ethernet, Wi-Fi or mobile network, etc.
[0079] S302: According to the saved correspondence between the network port of each network and the destination IP, search for the target network port corresponding to the destination IP.
[0080] In the embodiment of the present application, the terminal can be connected to multiple networks, wherein the terminal stores the network port corresponding to each network, and when the terminal sends a data packet through any network, the data packet is sent based on the network port corresponding to the network. Generally, one network corresponds to one network port.
[0081] The terminal stores the correspondence between the network port of each network and the preset fields of the destination IP. For example, the terminal stores the network port of Wi-Fi corresponding to the destination IP whose first 24 fields are a certain value. The terminal can determine the target network port used when sending the data packet based on the correspondence and the destination IP carried in the received data packet, and send the data packet based on the target network port.
[0082] In this embodiment of the present application, the target network port may be a network port corresponding to the target network used by the first device, or may be a network port corresponding to other networks.
[0083] S303: Send the data packet to a second device corresponding to the destination IP according to the target network port.
[0084] After the terminal determines the target network port, the terminal sends a data packet to the second device corresponding to the destination IP according to the target network port. Specifically, in an embodiment of the present application, the terminal determines the second device corresponding to the destination IP according to the target network port, and sends the data packet to the second device.
[0085] In the embodiment of the present application, the terminal stores the correspondence between the network port of each network and the destination IP. When the terminal receives a data packet sent by the first device through the target network, the terminal searches for the target network port corresponding to the destination IP in the correspondence according to the destination IP carried in the data packet, and sends the data packet to the second device corresponding to the destination IP through the target network port. In the embodiment of the present application, even if the first device and the second device are located in two different networks, the terminal can forward the data packet, thereby realizing multi-network intercommunication of the terminal.
[0086] In order to realize multi-network intercommunication of the terminal, based on the above embodiment, in the embodiment of the present application, the process of saving the correspondence between the network port of each network and the destination IP includes:
[0087] If a target instruction for storing the correspondence between the network port and the destination IP address of each network is received, a routing table corresponding to each stored network is determined;
[0088] Obtain other routing rules except the default routing rule in each routing table, wherein each other routing rule stores the corresponding relationship between the value of the preset field of the destination IP and the network port;
[0089] The other routing rules in each routing table are added to a preset local routing table, and the corresponding other routing rules are deleted in each routing table.
[0090] It can be seen from the above embodiments that the Android system in the terminal is an operating system based on the Linux system, and the Linux system stores a policy table and multiple routing tables, wherein the terminal selects the routing table through the policy table, and there are 3 rules in the policy table by default.
[0091] Figure 5 A schematic diagram of a policy table of a Linux system provided in an embodiment of the present application, such as the Figure 5 As shown in the figure, the number in the first column of each rule is the priority of the rule. The smaller the number, the higher the priority. The Linux system will give priority to the rules with high priority. The last column of each rule is the name of the routing table corresponding to the rule. Among them, the local routing table stores the routing rules when the destination IP is the terminal IP. The local routing table is very special and cannot be deleted or overwritten. The main routing table is a common table used to store the routes of the network connected to the Linux system, such as the routes of Ethernet, Wi-Fi and other networks. The default is an empty table, which is reserved for some subsequent processing.
[0092] The meaning of each rule is that packets sent from a certain address (all) query (lookup) a specified routing table. For example, the first rule is that packets sent from any address query the local routing table; the second rule is that packets sent from any address query the main routing table; the third rule is that packets sent from any address query the default routing table.
[0093] Among them, the main routing table of the Linux system contains various routing rules. The routing rules match the destination IP carried in the data packet. If the destination IP carried in the data packet meets a certain routing rule, the Linux system will send the data packet from the network port corresponding to this routing rule.
[0094] Figure 6 A schematic diagram of the main routing table of the Linux system provided in the embodiment of the present application, such as the Figure 6 As shown in the figure, the main routing table contains two routing rules. The routing rule corresponding to 192.168.120.0 / 24 indicates that the data packet with the first 24 bits of the destination IP being 192.168.120 is sent from the network port eth1; the other default rule is the default routing rule. When the destination IP carried in the data packet does not conform to the routing rule corresponding to 192.168.120.0 / 24, it is forwarded according to the default routing rule.
[0095] The above are the policy table and routing table of the Linux system. The Android system also has a policy table and routing table. However, unlike the Linux system, the Linux system saves the routing rules of each network in the main routing table, while the Android system establishes a routing table for each network. The policy table of the Android system has a policy rule corresponding to each routing table. This results in that after a terminal using the Android system receives a data packet sent by a device based on a certain network, the terminal will query the corresponding routing table of the network, that is, the terminal will use the network port corresponding to the network or the default network port corresponding to the network to send the data packet, that is, the terminal in the prior art does not support the problem of multi-network intercommunication.
[0096] Figure 7 A schematic diagram of a policy table in a terminal provided in an embodiment of the present application, such as the Figure 7As shown, the policy table of the terminal sets policy rules for each network. The terminal is connected to two Ethernets, and the network ports corresponding to the two Ethernets are eth0 and eth1 respectively. The terminal is also connected to Wi-Fi, and the network port corresponding to the Wi-Fi is wlan0. Among them, the Ethernet with network port eth0 corresponds to the routing table named 1027, the Ethernet with network port eth1 corresponds to the routing table named 1028, and the Wi-Fi with network port wlan0 corresponds to the routing table named 1029.
[0097] exist Figure 7 On the basis of Figure 8 A schematic diagram of a terminal of a routing table named 1029 in a terminal provided in an embodiment of the present application, such as the Figure 8 As shown in the figure, the routing table contains two routing rules. The routing rule corresponding to 192.168.36.0 / 24 indicates that the data packet with the first 24 bits of the destination IP being 192.168.36 is sent from the network port wlan0. The other default rule is the default routing rule. When the destination IP carried in the data packet does not conform to the routing rule corresponding to 192.168.36.0 / 24, it is forwarded according to the default routing rule.
[0098] Based on this, in the embodiment of the present application, in order to enable the terminal to realize the intercommunication of multiple networks, the technician can input a target instruction for saving the correspondence between the network port and the destination IP of each network into the terminal. After the terminal receives the target instruction, it executes the operation corresponding to the target instruction so that the other routing rules corresponding to each network except the default routing rule are saved in a local routing table with a higher priority than the routing table of each network. In this way, when the terminal receives a data packet and queries the routing rules in the routing table, the terminal can preferentially query the local routing table containing the routing rules of each network, thereby realizing the intercommunication of multiple networks of the terminal.
[0099] Specifically, in an embodiment of the present application, after the terminal receives the input target instruction for saving the correspondence between the network port and the destination IP of each network, the terminal determines the saved routing table corresponding to each network, and obtains other routing rules except the default routing rule in each routing table. The terminal adds the other routing rules in each routing table to the preset local routing table, and deletes the other routing rules in each routing table.
[0100] In the embodiment of the present application, each other routing rule stores the correspondence between the value of the preset field of the destination IP and the network port. For example, the destination IP with the first 24 bits of 192.168.36 corresponds to the network port wlan0, etc.
[0101] In the existing terminal, a routing table is established for each network. When the terminal receives a data packet sent by a device based on a certain network, the terminal will query the corresponding routing table of the network. In addition, the terminal will query two public routing tables, namely Figure 7 The first two rules in the local routing table and the routing table named 99. The local routing table is the same as the local routing table in the Linux system. It is the system default and is not allowed to be modified, and the local routing table will not affect the terminal's selection of network ports. The routing table named 99 is actually the legacy_system routing table, which is also a public routing table, but the legacy_system routing table is blank. Based on this feature of the legacy_system routing table, in the embodiment of the present application, the legacy_system routing table is determined as the preset local routing table, that is, in the embodiment of the present application, the other routing rules in each routing table are added to the legacy_system routing table.
[0102] Fig. 9 A schematic diagram of a legacy_system routing table with other routing rules added to each routing table provided in an embodiment of the present application, such as the Fig. 9 As shown in the figure, other routing rules in the two Ethernet and one Wi-Fi network routing tables are added to the legacy_system table, such as the routing rule for the Ethernet network port eth0 corresponding to the IP 192.168.1.0 / 24, the routing rule for the Ethernet network port eth1 corresponding to the IP 192.168.2.0 / 24, and the routing rule for the Wi-Fi network port wlan0 corresponding to the IP 192.168.36.0 / 24.
[0103] In order to find the target network port corresponding to the destination IP so that the terminal can send a data packet based on the target network port, based on the above embodiments, in the embodiment of the present application, the search for the target network port corresponding to the destination IP according to the saved correspondence between the network port of each network and the destination IP includes:
[0104] Accessing the local routing table to obtain each routing rule stored in the local routing table;
[0105] According to the correspondence between the value of the preset field of the destination IP stored in each routing rule and the network port, the target network port corresponding to the target value of the preset field of the destination IP is determined.
[0106] It can be seen from the above embodiment that the local routing table preset in the terminal stores other routing rules corresponding to each network except the default routing rule. Based on this, in the embodiment of the present application, after the terminal obtains the destination IP carried in the data packet, the terminal accesses the local routing table and obtains each routing rule stored in the local routing table.
[0107] In an embodiment of the present application, each routing rule stores the correspondence between the value of the preset field of the destination IP and the network port. The terminal can search for the target network port corresponding to the target value in the correspondence based on the target value of the preset field of the destination IP carried in the data packet.
[0108] For example, the routing rules saved in the local routing table of the terminal are that the destination IP with the first 24 bits of 192.168.1.0 corresponds to the network port eth0; the destination IP with the first 24 bits of 192.168.2.0 corresponds to the network port eth1; and the destination IP with the first 24 bits of 192.168.36.0 corresponds to the network port wlan0.
[0109] In order to implement the sending of the data packet, based on the above embodiments, in the embodiment of the present application, if the target network port is not found, the method further includes:
[0110] Determine a first routing table corresponding to the target network that is saved, and obtain a default routing rule saved in the first routing table;
[0111] According to the default port stored in the default routing rule, the data packet is sent to the second device corresponding to the destination IP.
[0112] In an embodiment of the present application, if the terminal does not find the target network port corresponding to the destination IP in the preset local routing table, the terminal will use the default port corresponding to the target network to send the data packet.
[0113] Specifically, in an embodiment of the present application, if the terminal does not find the target network port corresponding to the destination IP in the preset local routing table, the terminal determines the first routing table corresponding to the target network and obtains the default routing rule stored in the first routing table. The terminal sends the data packet to the second device corresponding to the destination IP according to the default port stored in the default routing rule.
[0114] In order to make each network in the terminal online and thus realize multi-network intercommunication, based on the above embodiments, in the embodiment of the present application, before receiving the data packet sent by the first device through the first network, the method further includes:
[0115] Receive the input power-on command and start the machine;
[0116] According to the pre-configured request message corresponding to each network, the current state of each network is set to online.
[0117] In the prior art, even if the terminal is connected to multiple networks, the terminal only allows one network to be online. Specifically, the terminal will match the appropriate network according to the received network request, and make the matched network online and other networks offline. The network request can specify various attributes of the network, such as transmission type, Internet access capability, etc. For example, if the network request specifies that Internet access capability is required, then when matching the network, the terminal will determine whether each network can provide Internet access capability. If Ethernet, Wi-Fi or data all meet the requirements, the network with high priority will be made online; if the network request specifies that the transmission type uses Wi-Fi, then only Wi-Fi meets the requirements, and the terminal will make Wi-Fi online.
[0118] Based on this, in an embodiment of the present application, the technicians save the request message of the network request corresponding to each network in the terminal in advance. The terminal makes the network corresponding to each network request online according to each network request, thereby realizing multi-network online of the terminal.
[0119] Specifically, the terminal is pre-configured with a request message for a network request corresponding to each network. After receiving a power-on command to power on, the terminal triggers a request message for each network request and sets the current state of each network to online. If a terminal is newly connected to a network while powered on, a technician needs to write a request message for the network request corresponding to the new network into the terminal.
[0120] For example, if there are two Ethernets and one Wi-Fi in the terminal, the technician will configure three request messages corresponding to the network requests, two of which specify the network transmission type as Ethernet, and the other network request specifies the network transmission type as Wi-Fi. Among them, there are two Ethernets in the terminal. When writing the request message, you can add the restriction conditions of the network port corresponding to each Ethernet in the request message corresponding to the Ethernet, or save the corresponding relationship between the request message and the network port corresponding to each Ethernet. For example, for the first network request of the first Ethernet, you can write the network port eth0 corresponding to the first Ethernet in the first request message of the first network request, or save the corresponding relationship between the first network request and the network port eth0 in the terminal. Based on this, when the terminal executes the first request message corresponding to the first network request, it makes the first Ethernet with network port eth0 online.
[0121] In addition, in an embodiment of the present application, there is a routing forwarding function in the terminal, and the routing forwarding function is a function for enabling the terminal to execute forwarding data packets. Specifically, if the routing forwarding function is not enabled in the terminal, after the terminal receives the data packet sent by the first device, the terminal obtains the destination IP carried in the data packet, and if the destination IP is inconsistent with the IP of the terminal, the terminal discards the data packet; correspondingly, if the routing forwarding function is enabled in the terminal, if the terminal recognizes that the destination IP is inconsistent with the IP of the terminal, the terminal will forward the data packet. Among them, the interface corresponding to the routing forwarding function is saved in the terminal, and if the routing forwarding function needs to be enabled, the terminal calls the interface.
[0122] In order to achieve multi-network intercommunication of the terminal, on the basis of the above embodiments, in the embodiment of the present application, the method further includes:
[0123] If the current mode is multi-network interconnection mode, determine whether there is any content saved in iptables;
[0124] If so, the content saved in iptables is copied to a preset target folder, and the content in the iptables is deleted.
[0125] In the embodiment of the present application, the terminal also stores iptables, wherein the iptables stores a rule that limits the multi-network intercommunication of the terminal. Based on this, if you want to achieve multi-network intercommunication of the terminal, you need to delete the rule in the iptables.
[0126] Specifically, in an embodiment of the present application, the terminal identifies whether the current mode is a multi-network intercommunication mode. If the current mode is a multi-network intercommunication mode, the terminal determines whether there is content in iptables. If so, the terminal copies the content saved in the iptables to a preset target folder and deletes the content in the iptables.
[0127] When the terminal identifies whether the current mode is the multi-network intercommunication mode, it can determine whether the routing forwarding function is currently turned on. Generally, the preset target folder is a folder created by the technician in the data directory of the terminal. The preset file can be named iptables_sav.dat, and the path of the preset folder is / data / iptables_sav.dat.
[0128] The terminal can copy the content saved in the iptables to the preset target folder and delete the content in the iptables through the following procedures:
[0129] iptables-save> / data / iptables_sav.dat
[0130] iptables –F
[0131] In order to disable multi-network intercommunication of the terminal, based on the above embodiments, in the embodiment of the present application, the method further includes:
[0132] If the current mode is not the multi-network intercommunication mode, determine whether there is any content saved in iptables;
[0133] If not, the content saved in the preset target folder is copied to the iptables, and the content in the target folder is deleted.
[0134] Based on the above embodiments, in the embodiments of the present application, if the terminal recognizes that the routing forwarding function is not currently turned on, that is, the current mode of the terminal is a non-multi-network intercommunication mode, the terminal determines whether there is content saved in iptables. If not, the terminal copies the content saved in the preset target folder to iptables and deletes the content in the target folder.
[0135] The terminal copies the contents saved in the preset target folder to iptables and deletes the contents in the target folder, which can be achieved through the following procedures:
[0136] iptables-restore < / data / iptables_sav.dat
[0137] iptables_sav.dat –F
[0138] The following is an introduction to the data packet forwarding method provided by the embodiment of the present application in conjunction with a specific embodiment:
[0139] Fig.10 A schematic diagram of a specific process of forwarding a data packet provided in an embodiment of the present application, such as the Fig.10 As shown, the process includes:
[0140] S1001: receiving an input power-on command and starting the computer.
[0141] The user sends a power-on command to the terminal through an external button of the terminal, and the terminal powers on after receiving the power-on command.
[0142] S1002: According to the pre-configured request message corresponding to each network, the current state of each network is set to online.
[0143] The terminal obtains a request message corresponding to each pre-configured network, and according to each request message, sets the current state of the network corresponding to each request message to online.
[0144] S1003: The terminal enables the routing forwarding function.
[0145] The terminal calls the interface corresponding to the routing forwarding function and turns on the routing forwarding function, so that the terminal can support multi-network intercommunication.
[0146] S1004: Copy the content saved in iptables to a preset target folder, and delete the content in iptables.
[0147] The terminal copies the content saved in iptables to a preset target folder and deletes the content in the iptables, so that the terminal is not restricted by the rules in iptables, and multi-network intercommunication of the terminal is realized.
[0148] S1005: Receive a data packet sent by the first device through the target network, and obtain a destination IP address carried in the data packet.
[0149] The terminal receives the data packet sent by the first device through the target network, and obtains the destination IP carried in the data packet. If the destination IP is inconsistent with the IP of the terminal, the terminal forwards the data packet.
[0150] S1006: Access the local routing table to obtain each routing rule stored in the local routing table; determine the target network port corresponding to the target value of the preset field of the destination IP stored in each routing rule and the network port.
[0151] The terminal obtains the target value of the preset field of the destination IP, accesses the local routing table, and each routing rule stored in the local routing table. The terminal determines the target network port corresponding to the target value according to the corresponding relationship between the value of the preset field of the destination IP stored in each routing rule and the network port.
[0152] S1007: Send the data packet to the second device corresponding to the destination IP according to the target network port.
[0153] Fig.11 A schematic diagram of the structure of a data packet sending device provided in an embodiment of the present application, such as the Fig.11 As shown, the device comprises:
[0154] The receiving module 1101 is used to receive a data packet sent by the first device through the target network;
[0155] The processing module 1102 is used to obtain the destination IP carried in the data packet; and search for the target network port corresponding to the destination IP according to the stored correspondence between the network port of each network and the destination IP;
[0156] The sending module 1103 is used to send the data packet to the second device corresponding to the destination IP according to the target network port.
[0157] In a possible implementation, the processing module 1102 is specifically used to determine the saved routing table corresponding to each network if an input target instruction for saving the correspondence between the network port and the destination IP of each network is received; obtain other routing rules in each routing table except the default routing rule, wherein each other routing rule saves the correspondence between the value of the preset field of the destination IP and the network port; add the other routing rules in each routing table to the preset local routing table, and delete the corresponding other routing rules in each routing table.
[0158] In a possible implementation, the processing module 1102 is specifically used to access the local routing table and obtain each routing rule stored in the local routing table; and determine the target network port corresponding to the target value of the preset field of the destination IP stored in each routing rule and the network port.
[0159] In a possible implementation, the processing module 1102 is further configured to determine a first routing table corresponding to the target network that is stored, and obtain a default routing rule stored in the first routing table;
[0160] The sending module 1103 is further configured to send the data packet to the second device corresponding to the destination IP according to the default port stored in the default routing rule.
[0161] In a possible implementation manner, the receiving module 1101 is further configured to receive an input power-on instruction and perform power-on;
[0162] The processing module 1102 is further configured to set the current state of each network to online according to the pre-configured request message corresponding to each network.
[0163] In a possible implementation, the processing module 1102 is further used to determine whether there is content stored in iptables if the current mode is a multi-network intercommunication mode; if so, copy the content stored in iptables to a preset target folder and delete the content in iptables.
[0164] In a possible implementation, the processing module 1102 is also used to determine whether there is content stored in iptables if the current mode is a non-multi-network intercommunication mode; if not, copy the content stored in a preset target folder to the iptables and delete the content in the target folder.
[0165] Based on the same inventive concept, Fig.12 Another schematic diagram of the structure of the terminal provided in the embodiment of the present application is as follows: Fig.12 As shown, it includes: one or more (including two) processors 1201 and a communication interface 1202.
[0166] Optionally, the terminal further includes a memory 1203, which may include a read-only memory and a random access memory, and provides operation instructions and data to the processor. A portion of the memory may also include a non-volatile random access memory (NVRAM).
[0167] In some embodiments, Fig.12 As shown, the memory 1203 stores the following elements, execution modules or data structures, or their subsets, or their extended sets.
[0168] like Fig.12 As shown, in some embodiments of the present application, corresponding operations are performed by calling operation instructions stored in the memory 1203 (the operation instructions may be stored in the operating system).
[0169] like Fig.12 As shown, the processor 1201 controls the processing operation of the head-end device, and the processor can also be called a central processing unit (CPU).
[0170] like Fig.12 As shown, the memory 1203 may include a read-only memory and a random access memory, and provide instructions and data to the processor. A portion of the memory 1203 may also include an NVRAM. For example, in an application, the communication interface and the memory are coupled together through a bus system 1204, wherein the bus system 1204 may include a power bus, a control bus, and a status signal bus in addition to a data bus. However, for the sake of clarity, in Fig.12 Various buses are labeled as bus system 1204.
[0171] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0172] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0173] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0174] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0175] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A data packet sending method, applied to a terminal, characterized in that: The method comprises: Receive a data packet sent by the first device through the target network, and obtain a destination IP address carried in the data packet; According to the saved correspondence between the network port of each network and the destination IP, find the target network port corresponding to the destination IP; Sending the data packet to a second device corresponding to the destination IP according to the target network port; The process of storing the correspondence between the network port of each network and the destination IP address includes: If a target instruction for storing the correspondence between the network port and the destination IP address of each network is received, a routing table corresponding to each stored network is determined; Obtain other routing rules except the default routing rule in each routing table, wherein each other routing rule stores the corresponding relationship between the value of the preset field of the destination IP and the network port; The other routing rules in each routing table are added to a preset local routing table, and the corresponding other routing rules are deleted in each routing table.
2. The method according to claim 1, characterized in that The searching for the target network port corresponding to the destination IP according to the stored correspondence between the network port of each network and the destination IP comprises: Accessing the local routing table to obtain each routing rule stored in the local routing table; According to the correspondence between the value of the preset field of the destination IP stored in each routing rule and the network port, the target network port corresponding to the target value of the preset field of the destination IP is determined.
3. The method according to claim 1, characterized in that If the target network port is not found, the method further includes: Determine a first routing table corresponding to the target network that is saved, and obtain a default routing rule saved in the first routing table; According to the default port stored in the default routing rule, the data packet is sent to the second device corresponding to the destination IP.
4. The method according to claim 1, characterized in that: Before receiving the data packet sent by the first device through the first network, the method further includes: Receive the input power-on command and start the machine; According to the pre-configured request message corresponding to each network, the current state of each network is set to online.
5. The method according to claim 4, characterized in that The method further comprises: If the current mode is multi-network interconnection mode, determine whether there is any content saved in iptables; If so, the content saved in iptables is copied to a preset target folder, and the content in the iptables is deleted.
6. The method according to claim 4, characterized in that The method further comprises: If the current mode is not the multi-network intercommunication mode, determine whether there is any content saved in iptables; If not, the content saved in the preset target folder is copied to the iptables, and the content in the target folder is deleted.
7. A data packet sending device, applied to a terminal, characterized in that: The device comprises: A receiving and processing module, configured to receive a data packet sent by the first device through a target network, and obtain a destination IP address carried in the data packet; A search module is used to search for a target network port corresponding to the destination IP according to the stored correspondence between the network port of each network and the destination IP; A sending module, used for sending the data packet to a second device corresponding to the destination IP according to the target network port; Among them, the processing module is specifically used to determine the saved routing table corresponding to each network if an input target instruction for saving the correspondence between the network port and the destination IP of each network is received; obtain other routing rules in each routing table except the default routing rule, wherein each other routing rule saves the correspondence between the value of the preset field of the destination IP and the network port; add the other routing rules in each routing table to the preset local routing table, and delete the corresponding other routing rules in each routing table.
8. A terminal, characterized in that: The terminal comprises: Display, processor and memory; The display is used to display the screen display area; The memory is used to store the processor executable instructions; The processor is configured to execute the instructions to implement the data packet sending method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: It stores a computer program, which, when executed by a processor, implements the steps of the data packet sending method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Android-system-based distribution method through multi-network route policy
CN103957572A