Structure and Principle Analysis of the packet capture Module Based on Linux

Source: Internet
Author: User
Structure and Principle Analysis of the packet capture module based on Linux-Linux Enterprise Application-Linux server application information. The following is a detailed description. This section discusses the structural features of the monitoring layer data packet capture module, discusses its principles in detail, and describes some important functions of the program that implements the data packet capture function.

1. Structure of the data packet capture module

The packet capture module is used to monitor and verify network traffic. It can intercept or read packets at various Protocol levels in the OSI protocol model on the network.

The data Packet capture program designed in this article can capture Raw Packet through the original Socket interface. When a data Packet reaches the network interface, the data packet capture program reads the captured data packets directly from the cache for data analysis and processing.

2. Principle Analysis of the data packet capture module

(1) network card setting principle

In an actual system, data is sent and received by the Network Adapter. The network adapter receives the transmitted data. The program in the network adapter receives the destination MAC address of the data frame, determine whether or not to receive the message based on the receiving mode set by the NIC driver on the computer. For NICs, there are generally four receiving modes: broadcast mode multicast mode, direct mode, and hybrid mode. The packet capture program first makes the network interface (NIC) in a hybrid state, which can intercept the content on the network and analyze the content of the data in real time through corresponding software processing, prepare for data packet filtering.

(2) description of basic functions

In this article, we will write a data packet capture program in C language on the Linux host, and many predefined functions in Linux will be used in the program. In this section, we will describe the functions and usage features of these basic functions.

1) ioctl function definition

Ioctl () functions are very complex and can control the attributes of various files. It is used to control the underlying device parameters of special files. These special files usually refer to terminals, sockets, and interfaces. The ioctl function is prototype: int ioctl (int handle, int cmd [, int * argdx, int argcx]);

2) socket function definition

There are two common Socket types: stream Socket (SOCK_STREAM) and PACKET Socket (SOCK_DGRAM ). Streaming is a connection-oriented Socket for connection-oriented TCP Service applications; datagram Socket is a connectionless Socket for connectionless UDP Service applications. The prototype of the Socket function is: int socket (int domain, int type, int protocol );

3) recvfrom () function definition

The recvfrom () function is used to receive data packets. The recvfrom () function is a function with the "blocking I/O" feature. It can temporarily suspend waiting without the arrival of data packets, after receiving the data packet, activate the next step. The recvfrom () function is prototype:
  
QUOTE:
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.