linux - 如何在内核代码中查找 ssh 连接的 IP?

标签 linux linux-kernel linux-device-driver

我想使用内核代码找出 ssh 连接的 IP。但是,我无法在 Internet 上找到任何合适的引用。

我尝试使用 usermodehelper API,但它似乎没有在内核中提供输出。

非常感谢任何帮助!

最佳答案

假设 3298 是您感兴趣的进程的 pid。在 userpsace 中,我可以调用

ls -l /proc/3298/fd

它会列出类似的东西

lrwx------ 1 name name 64 Apr  6 11:27 0 -> /dev/pts/2
lrwx------ 1 name name 64 Apr  6 11:27 1 -> /dev/pts/2
lrwx------ 1 name name 64 Apr  6 11:27 2 -> /dev/pts/2
lrwx------ 1 name name 64 Apr  6 11:27 3 -> socket:[50256]
lrwx------ 1 name name 64 Apr  6 11:37 4 -> /dev/pts/2
lrwx------ 1 name name 64 Apr  6 11:37 5 -> /dev/pts/2
lrwx------ 1 name name 64 Apr  6 11:37 6 -> /dev/pts/2

我们现在知道 fd 3(而且只有 fd 3)是您要查找的文件描述符。你的信息应该在 fd 3 中。你应该能够通过查看内核源代码如何实现/proc/pid/fd 在内核空间中做同样的事情。

关于linux - 如何在内核代码中查找 ssh 连接的 IP?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36416712/

相关文章:

linux - 使用 bash 计算 Linux 上最小化的窗口

c - X86 中的 C 函数需要多少堆栈和堆(以字节为单位)

c - 不清楚的结构变量用法 - C

c - 自定义字符设备的读取系统调用的回调函数(scull read)在使用 $cat 读取时被无限次调用

c - Linux 内核编程 : "Unable to handle kernel NULL pointer dereference"

linux - 使用 crontab 从数据库中删除旧记录

linux - 如何证明 RS 232 全调制解调器、RS 422 工作 PC 到 PC 和 LOOP BACK

ubuntu - 如何将 PC 连接到 ubuntu Beagle 板

Linux 命令行搜索和替换

linux - 定义了全局描述符和局部描述符表的数据结构的文件?