* [PATCH] iproute2: Add ll_index_to_addr function
@ 2009-10-15 18:53 David Ward
2009-12-01 23:54 ` Stephen Hemminger
0 siblings, 1 reply; 2+ messages in thread
From: David Ward @ 2009-10-15 18:53 UTC (permalink / raw)
To: netdev; +Cc: David Ward
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>
---
include/ll_map.h | 2 ++
lib/ll_map.c | 21 +++++++++++++++++++++
2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/include/ll_map.h b/include/ll_map.h
index c4d5c6d..752b827 100644
--- a/include/ll_map.h
+++ b/include/ll_map.h
@@ -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__ */
diff --git a/lib/ll_map.c b/lib/ll_map.c
index c1d61a9..7c0bea2 100644
--- a/lib/ll_map.c
+++ b/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];
--
1.5.5.6
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-12-01 23:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-15 18:53 [PATCH] iproute2: Add ll_index_to_addr function David Ward
2009-12-01 23:54 ` Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).