当前位置:网站首页>Raw socket grabs packets, and packets on some ports cannot be caught
Raw socket grabs packets, and packets on some ports cannot be caught
2022-07-27 11:20:00 【lqw198421】
background
TCP Packet filter items , After deploying the execution program to the real disk , Found some port( Or connecting ) The message of can be captured , But some connected messages cannot be captured , And according to Murphy's law , The target message is not captured (dog head);
location
1、 Recall the whole execution process , No problem found , And also added printing , It is found that the target is indeed not captured port The connection of , Instead of being captured and filtered to because of other conditions ;
2、 This problem can only be reproduced in the real offer environment , And locally docker The problem cannot be reproduced under , But the real offer debugging should be completed by Party B , Very trouble , So Wen long suggested that tcpreplay To reproduce ; Tossed about for a moment , Find out tcpreplay You can only specify the sending condition of the local specific network card ( In fact, these packages cannot reach the application level of the destination , Even if the destination plane can arrive ), What I need is to monitor the reception of the network card ! Later, teacher Shen said that you can set , To make 2 Servers , An analog transmitter ( adopt tcpreplay), An analog receiver ( Be careful : This reception is only at the network card level , Can't reach the upper floor , But for my program , It should be ok ?– Later I thought about , Maybe not , You need to determine raw socket What level is monitored ), It's a toss in the back tcpreplay Of tcpprep and tcprewrite, Object files are also generated , But it failed in the end ;
3、 Look back and continue to look at the code , Although I feel impossible , But a dead horse should be a living horse doctor , Try to release raw socket, From the original only monitor TCP My bag , Change to monitor all network packets , Find a solution to ;
solve
Specific code changes :
The original raw socket Initialize settings :
AF_INET, SOCK_RAW, IPPROTO_TCP
Revised raw socket Initialize settings :
PF_PACKET, SOCK_RAW, htons(ETH_P_IP)
In addition, we need to pay attention to :
Revised raw socket The intercepted message content , It contains etheric head (ether_header) Of , So it's parsing buf When , You need to pay attention to crossing this many etheric head , Then it is captured in the original setting ip_header, Then proceed to the original parsing process ;
summary
1、 Before the cause is found , Don't give up any possible way because of your existing knowledge ;
2、 Try not to build your own wheels , Try to search existing tools ;
边栏推荐
- The longest ascending subsequence model acwing 1016. The sum of the largest ascending subsequence
- How to build a real-time development platform to deeply release the value of enterprise real-time data?
- 背包模型 AcWing 423. 采药
- SQL Server2000数据库错误
- Remember not to copy your group work, students. Fortunately, you only passed two questions. Don't have an accident
- 6 find the smallest letter larger than the target letter
- Data assets are king. How to analyze the relationship between enterprise digital transformation and data asset management?
- Kangaroo cloud stack based on CBO in spark SQL optimization
- 中国剩余定理 AcWing 204. 表达整数的奇怪方式
- Longest ascending subsequence model acwing 1012. Sister Cities
猜你喜欢

栈 AcWing 3302. 表达式求值

Redis high availability principle

ACM warm-up Exercise 2 in 2022 summer vacation (summary)

Introduction to software vulnerability analysis (I)

博弈论 AcWing 891. Nim游戏

求组合数 AcWing 888. 求组合数 IV

Find the combinatorial number acwing 889. 01 sequence satisfying the condition

Instructions for mock platform

Digital triangle model acwing 275. pass note

The longest ascending subsequence model acwing 1016. The sum of the largest ascending subsequence
随机推荐
11 wrong set
Wilderness search --- search iterations
背包模型 AcWing 423. 采药
最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼
Derive the detailed expansion of STO double center kinetic energy integral
7 row K with the weakest combat effectiveness in the matrix
SQL Server2000 database error
高斯消元 AcWing 883. 高斯消元解线性方程组
The influence of the number of non-zero values in the picture on Classification
Find the combination number acwing 886. find the combination number II
Taishan Office Technology Lecture: scaling and opening files
The difference of iteration number and information entropy
Kangaroo cloud stack based on CBO in spark SQL optimization
ACM warm-up Exercise 2 in 2022 summer vacation (summary)
Stack acwing 3302. Expression evaluation
MySQL installation (RPM package)
Asustek unparalleled, this may be the best affordable high brush thin notebook on the screen
Yum source installation
How to create a.Net image with diagnostic tools
最长上升子序列模型 AcWing 1016. 最大上升子序列和