mirror of
https://git.kernel.org/pub/scm/network/iproute2/iproute2.git
synced 2024-11-15 22:15:13 +08:00
iproute2: Add ll_index_to_addr function
After calling ll_init_map, all of the information stored in the link-layer map can be retrieved by function calls (ll_index_to_*), except for the link-layer address. This patch fills the gap by adding a ll_index_to_addr function. Changes welcome. Signed-off-by: David Ward <david.ward@ll.mit.edu>
This commit is contained in:
parent
71e5815105
commit
ee7ba9875d
@ -9,5 +9,7 @@ extern const char *ll_index_to_name(unsigned idx);
|
||||
extern const char *ll_idx_n2a(unsigned idx, char *buf);
|
||||
extern int ll_index_to_type(unsigned idx);
|
||||
extern unsigned ll_index_to_flags(unsigned idx);
|
||||
extern unsigned ll_index_to_addr(unsigned idx, unsigned char *addr,
|
||||
unsigned alen);
|
||||
|
||||
#endif /* __LL_MAP_H__ */
|
||||
|
21
lib/ll_map.c
21
lib/ll_map.c
@ -134,6 +134,27 @@ unsigned ll_index_to_flags(unsigned idx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned ll_index_to_addr(unsigned idx, unsigned char *addr,
|
||||
unsigned alen)
|
||||
{
|
||||
struct idxmap *im;
|
||||
|
||||
if (idx == 0)
|
||||
return 0;
|
||||
|
||||
for (im = idxmap[idx&0xF]; im; im = im->next) {
|
||||
if (im->index == idx) {
|
||||
if (alen > sizeof(im->addr))
|
||||
alen = sizeof(im->addr);
|
||||
if (alen > im->alen)
|
||||
alen = im->alen;
|
||||
memcpy(addr, im->addr, alen);
|
||||
return alen;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned ll_name_to_index(const char *name)
|
||||
{
|
||||
static char ncache[16];
|
||||
|
Loading…
Reference in New Issue
Block a user