rfc: print mac addr
hi list,
must (if not all) net drivers contain something like this to print a mac addr:
for (i = 0; i < 6; i++)
printk("%2.2x%c", dev->dev_addr[i],i = 5 ? '\n' : ':');
I think it would be usefull to add a helper function.
simple question:
1. is there such a function ?
2. where to add ? each driver ? or is there a common place i do not know about ?
re,
walter
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
Hi walter
Quoted 4 lines
for (i = 0; i < 6; i++)
printk("%2.2x%c", dev->dev_addr[i],i = 5 ? '\n' : ':');
1. Please post an example or the file name!
2. Are you sure that this portion of code isn't into a DEBUG block (something like #ifdef DEBUG_xx)?
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 4 lines · walter harms
hi list,
must (if not all) net drivers contain something like this to print a mac addr:
If that's so, then yes, a helper function is a good idea IMO.
Quoted 6 lines
for (i = 0; i < 6; i++)
printk("%2.2x%c", dev->dev_addr[i],i == 5 ? '\n' : ':');I think it would be usefull to add a helper function. simple question:
1. is there such a function ?
If your claim that most drivers do it on their own, then I hope/guess that there is not already such a helper function...
I don't see one in include/linux/*.h.
Quoted 2 lines
2. where to add ? each driver ? or is there a common place i do not know about ?
Either
(1) inline in include/linux/{if_ether.h or etherdevice.h or netdevice.h} although I prefer one of the first two since this looks ethernet-specific (due to the "i < 6").
And change the 6 to ETH_ALEN if this is for ethernet MAC addresses. And put a space between comma and i: ",i" should be ", i".
or
(2) in net/core/dev.c.
Signature · 1 line
~Randy
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 7 lines · Paolo Teti
Hi walter
Quoted 3 lines
for (i = 0; i < 6; i++)
printk("%2.2x%c", dev->dev_addr[i],i = 5 ? '\n' : ':');1. Please post an example or the file name!
cd linux/drivers/net
grep dev_addr *.c | grep printk
Quoted 3 lines
2. Are you sure that this portion of code isn't into a DEBUG block (something like #ifdef
DEBUG_xx)?
i did not check every file but looked into a few and the pattern is all the same. maybe some of them are inside a #ifdef debug the few i looked are not.
i know gregKH added a few dev helper macros but i can not find them anymore. The idea is to provide a function like:
void print_mac(struct net_device *dev)
{
int i;
printk(KERN_INFO);
for (i = 0; i < MAX_ADDR_LEN; i++)
printk("%2.2x%c", dev->dev_addr[i],i = (MAX_ADDR_LEN-1) ? '\n' : ':');
}
may you like to return a string ?
re,
walter
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 8 lines
(1) inline in
include/linux/{if_ether.horetherdevice.hornetdevice.h} although I prefer one of the first two since this looks ethernet-specific (due to the "i < 6").
And change the 6 toETH_ALENif this is for ethernet MAC addresses. And put a space between comma and i: ",i" should be ", i".or
(2) innet/core/dev.c.
I would definitely pick the second option. There's no reason like performance for such a helper to be an inline function, so we should save .text by moving it out of line.
- R.
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 16 lines · On Tue, 06 Dec 2005 18:11:48 +0100 walter harms wrote:
Quoted 7 lines · Paolo Teti
Hi walter
Quoted 3 lines
for (i = 0; i < 6; i++)
printk("%2.2x%c", dev->dev_addr[i],i == 5 ? '\n' : ':');1. Please post an example or the file name!
cd linux/drivers/net
grepdev_addr*.c | grep printkQuoted 3 lines
2. Are you sure that this portion of code isn't into a DEBUG block (something like #ifdef
DEBUG_xx)?
Quoted 6 lines
i did not check every file but looked into a few and the pattern is all the same. maybe some of them are inside a #ifdef debug the few i looked are not.
i know gregKH added a few dev helper macros but i can not find them anymore. The idea is to provide a function like:
see include/linux/device.h: dev_printk() and friends.
Quoted 10 lines
void
print_mac(struct net_device *dev){ int i; printk(KERN_INFO); for (i = 0; i < MAX_ADDR_LEN; i++) printk("%2.2x%c", dev->dev_addr[i],i == (MAX_ADDR_LEN-1) ? '\n': ':');
}
may you like to return a string ?
I would just print it (like you did) instead of return a string (I think).
MAX_ADDR_LEN may want to be a variable in this function so that differing MAC address lengths can be supported.
And put a space between ",i".
Thanks.
---
~Randy
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors