-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlab1_devices.c
80 lines (70 loc) · 2.12 KB
/
lab1_devices.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* **************** LF331:1.6 s_24/lab1_devices.c **************** */
/*
* The code herein is: Copyright the Linux Foundation, 2011
*
* This Copyright is retained for the purpose of protecting free
* redistribution of source.
*
* URL: http://training.linuxfoundation.org
* email: [email protected]
*
* The primary maintainer for this code is Jerry Cooperstein
* The CONTRIBUTORS file (distributed with this
* file) lists those known to have contributed to the source.
*
* This code is distributed under Version 2 of the GNU General Public
* License, which you should have received with the source.
*
*/
/*
* Examining Network Devices
*
* All network devices are linked together in a list. You can get a
* pointer to the head of the list and then *walk through it using:
*
* struct net_device *first_net_device (&init_net);
* struct net_device *next_net_device(struct net_device *dev);
*
* or even easier:
*
* for_each_netdev(&init_net, dev) { ..... }
*
* Write a module that works its way down the list and prints out
* information about each driver.
* This should include the name, any associated irq, and various other
* parameters you may find interesting.
* Try doing this with your previous simple network module loaded.
@*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/netdevice.h>
static void printit(struct net_device *dev) {
printk(KERN_INFO
"name = %6s irq=%4d trans_start=%12lu last_rx=%12lu\n",
dev->name, dev->irq, dev->trans_start, dev->last_rx);
}
static int __init my_init(void)
{
struct net_device *dev;
printk(KERN_INFO "Hello: module loaded at 0x%p\n", my_init);
/* either of these methods will work */
for_each_netdev(&init_net, dev)
printit(dev);
/*
dev = first_net_device(&init_net);
while (dev) {
printit(dev);
dev = next_net_device(dev);
}
*/
return 0;
}
static void __exit my_exit(void)
{
printk(KERN_INFO "Module Unloading\n");
}
module_init(my_init);
module_exit(my_exit);
MODULE_AUTHOR("Jerry Cooperstein");
MODULE_DESCRIPTION("LF331:1.6 s_24/lab1_devices.c");
MODULE_LICENSE("GPL v2");