#include <linux/uaccess.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/kernel_stat.h>
#include <linux/platform_device.h>
#include <linux/kobject.h>
#include <linux/sysfs.h>
#include <net/neighbour.h>
#include <net/arp.h>
#include <linux/if_arp.h>
/**
* sudo arp-scan -I eth0 --localnet
*/
struct device *dev;
#define HBUFFERLEN 30
void cb(struct neighbour *nb, void *a) {
int k,j;
char tbuf[16];
char hbuffer[HBUFFERLEN];
struct net_device *dev = nb->dev;
int hatype = dev->type;
if (ARPHRD_LOOPBACK == hatype)
return;
sprintf(tbuf, "%pI4", nb->primary_key);
pr_info("primary_key, %s\n", tbuf);
for (k = 0, j = 0; k < HBUFFERLEN - 3 && j < dev->addr_len; j++) {
hbuffer[k++] = hex_asc_hi(nb->ha[j]);
hbuffer[k++] = hex_asc_lo(nb->ha[j]);
hbuffer[k++] = ':';
}
if (k != 0)
--k;
hbuffer[k] = 0;
pr_info("mac, %s\n", hbuffer);
}
int myprobe(struct platform_device *pdev) {
int cookie = 0;
dev = &pdev->dev;
neigh_for_each(&arp_tbl, cb, &cookie);
return 0;
}
int myremove(struct platform_device *pdev) {
return 0;
}
struct of_device_id my_of_match_table =
{ .compatible = "my_platform_device_003", };
struct platform_driver my_platform_driver = { .driver =
{ .of_match_table = &my_of_match_table, .name = "my-platform-driver",
.owner = THIS_MODULE, }, .probe = myprobe, .remove = myremove, };
module_platform_driver(my_platform_driver);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Andy");
MODULE_DESCRIPTION("andy one-key driver");
MODULE_ALIAS("one-key");
linux内核邻居子系统入门之打印局域网内所有机器的ip和mac地址
最新推荐文章于 2023-02-13 15:07:44 发布