snmp v1 get请求优化---调试net-snmp

1背景

上一篇snmp v1 get请求优化(上) 本来是想直接看源码来寻找get请求怎么响应的,但是没调试的情况下不好验证猜测,所以有了这篇。

2 源码调试 方案

2.1 window系统 ---先跳过,有空再折腾

先说系统,window系统 snmp wireshark 抓包 这里就下载过一次源码,没过了make那一步,用了msys后放弃了,之后有时间再调试吧。

2.2 linux系统---问就是ubuntu

今天是重新折腾ubuntu系统,之前vmbox一直用了ubuntu16.04的,更新vmbox后,重新选了ubuntu20.04的,要装vscode,直接用了桌面端,使用了阿里的 mirrors.aliyun.com/ubuntu-rele...

使用了迅雷的下载的p2p镜像,vmbox安装没啥说的,改改默认的密码就行(如果你习惯当我没说)

2.3 ubuntu的一些准备工作

输入法

Ubuntu 上最好用的中文输入法是什么

arduino 复制代码
sudo apt-get install fcitx
sudo apt-get install fcitx-googlepinyin

如果使用root,安装后重启或者注销,不然fcitx找不到

vscode安装

shell 复制代码
sudo snap install code --classic

vscode 终端提权

上面安装完成后,打开vscode的终端,使用sudo会有如下的提示

xxxx is not in the sudoers file. This incident will be reported

通过 root 用户添加权限,PS 注销或者重启

bash 复制代码
# 1. 切换到 root 用户
su -  # 输入 root 密码

# 2. 将用户加入 sudo 组
usermod -aG sudo xxxxxx

# 3. 退出 root
exit

# 4. 重新登录用户
su - xxxxxx

vscode 插件

2.4 下载源码以及调试

snmp v1 get请求优化(上) 这里使用了 5.9.4 的源码,下载tar包,并解压,又是新一轮的尝试

js 复制代码
tar zxvf net-snmp-5.9.4.tar.gz 
cd net-snmp-5.9.4/

sudo apt update
sudo apt install build-essential libtool autoconf gdb
sudo apt install libssl-dev libwrap0-dev

sudo apt install net-tools
sudo apt install vim 


./configure --prefix=/usr/local/net-snmp --enable-debug --enable-ipv6
make -j1 && sudo make install

PS:configure 默认版本选 1

这之后就是配置文件了,端口还是1161了,161不尝试了。。。

bash 复制代码
sudo vim /usr/local/net-snmp/share/snmp/snmpd.conf

sysLocation "Debug Lab"
sysContact admin@lab
agentAddress udp:1161
rocommunity public 127.0.0.1
disableIPv6 yes

vscode启动调试的配置文件 .vscode/launch.json

ruby 复制代码
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug snmpd",
            "type": "cppdbg",
            "request": "launch",
            "program": "/usr/local/net-snmp/sbin/snmpd", // 修改为你的实际路径
            "args": ["-f", "-Lo"], // -f前台运行 -L输出到控制台
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "启用gdb美化打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            //"preLaunchTask": "build-net-snmp" // 可选:添加编译任务
        }
    ]
}

.vscode/tasks.json

json 复制代码
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build-net-snmp",
            "type": "shell",
            "command": "make -j1 && sudo make install",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

preLaunchTask 基本可以忽略,等的时间很长,还不如终端执行,要输入密码的。

3 最终效果

相关推荐
鬼魅-952724 分钟前
VS+Qt中使用QCustomPlot绘制曲线标签(附源码)
c++·qt
xdlka2 小时前
C++初学者4——标准数据类型
开发语言·c++·算法
云边有个稻草人3 小时前
【C++】第十九节—一文万字详解 | AVL树实现
数据结构·c++·avl树·avl树的插入·avl树的旋转·avl树实现·avl树的结构
略无慕艳意8 小时前
【笔记】Visual Studio 2022 入门指南
c++·c·cmake·microsoft visual studio 2022
遇见尚硅谷12 小时前
C语言:20250728学习(指针)
c语言·开发语言·数据结构·c++·笔记·学习·算法
☆璇12 小时前
【C++】C/C++内存管理
c语言·开发语言·c++
铭哥的编程日记13 小时前
《C++ list 完全指南:从基础到高效使用》
开发语言·c++·list
岁忧14 小时前
(LeetCode 面试经典 150 题 ) 155. 最小栈 (栈)
java·c++·算法·leetcode·面试·go
铭哥的编程日记16 小时前
《C++继承详解:从入门到理解公有、私有与保护继承》
c++
qq_4335545416 小时前
C++ 哈希算法、贪心算法
开发语言·c++·哈希算法