#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 <linux/in.h>
#include <net/neighbour.h>
#include <net/arp.h>
#include <linux/if_arp.h> /** type */
#include <net/ip.h>
#include <net/netevent.h>
#include <linux/inetdevice.h>
/**
* sudo arp-scan -I eth0 --localnet
*/
#define HBUFFERLEN 30
struct net_device *mynet_device;
int myprobe(struct platform_device *pdev) {
int k, j;
char hbuffer[HBUFFERLEN];
struct in_ifaddr *ip;
mynet_device = dev_get_by_name(&init_net, "eth0");
pr_info("mynet_device name: %s\n", mynet_device->name);
pr_info("mynet_device type: %d\n", mynet_device->type);
for (k = 0, j = 0; k < HBUFFERLEN - 3 && j < mynet_device->addr_len; j++) {
hbuffer[k++] = hex_asc_hi(mynet_device->perm_addr[j]);
hbuffer[k++] = hex_asc_lo(mynet_device->perm_addr[j]);
hbuffer[k++] = ':';
}
if (k != 0)
--k;
hbuffer[k] = 0;
pr_info("mac: %s\n", hbuffer);
ip = mynet_device->ip_ptr->ifa_list;
printk(KERN_INFO "ipaddr=%pI4\n",
&(ip->ifa_local));
return 0;
}
int myremove(struct platform_device *pdev) {
pr_info("myplatformdriver myremove \n");
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");
这里是全部的代码