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的一些准备工作
输入法
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 基本可以忽略,等的时间很长,还不如终端执行,要输入密码的。