summaryrefslogtreecommitdiffstats
path: root/isys
diff options
context:
space:
mode:
authorChris Lumens <clumens@redhat.com>2009-05-21 11:26:37 -0400
committerChris Lumens <clumens@redhat.com>2009-05-22 13:11:37 -0400
commit14e7a456f546b3df2dd67d803436114b517e73ec (patch)
treeeda300558ec2e4cae023d4527c4f0549b7260316 /isys
parentfbda3bde2593e1328779d612fb65bdd65e877406 (diff)
downloadanaconda-14e7a456f546b3df2dd67d803436114b517e73ec.tar.gz
anaconda-14e7a456f546b3df2dd67d803436114b517e73ec.tar.xz
anaconda-14e7a456f546b3df2dd67d803436114b517e73ec.zip
Add a function to convert MAC addresses to device names.
Diffstat (limited to 'isys')
-rw-r--r--isys/iface.c48
-rw-r--r--isys/iface.h5
2 files changed, 53 insertions, 0 deletions
diff --git a/isys/iface.c b/isys/iface.c
index 137180275..e139e7476 100644
--- a/isys/iface.c
+++ b/isys/iface.c
@@ -222,6 +222,54 @@ char *iface_ip2str(char *ifname, int family) {
return NULL;
}
+/* Given an interface's MAC address, return the name (e.g., eth0) in human
+ * readable format. Return NULL for no match
+ */
+char *iface_mac2device(char *mac) {
+ struct nl_handle *handle = NULL;
+ struct nl_cache *cache = NULL;
+ struct rtnl_link *link = NULL;
+ struct nl_addr *mac_as_nl_addr = NULL;
+ char *retval = NULL;
+ int i, n;
+
+ if (mac == NULL) {
+ return NULL;
+ }
+
+ if ((mac_as_nl_addr = nl_addr_parse(mac, AF_LLC)) == NULL) {
+ return NULL;
+ }
+
+ if ((cache = _iface_get_link_cache(&handle)) == NULL) {
+ return NULL;
+ }
+
+ n = nl_cache_nitems(cache);
+ for (i = 0; i <= n; i++) {
+ struct nl_addr *addr;
+
+ if ((link = rtnl_link_get(cache, i)) == NULL) {
+ continue;
+ }
+
+ addr = rtnl_link_get_addr(link);
+
+ if (!nl_addr_cmp(mac_as_nl_addr, addr)) {
+ retval = strdup(rtnl_link_get_name(link));
+ rtnl_link_put(link);
+ break;
+ }
+
+ rtnl_link_put(link);
+ }
+
+ nl_close(handle);
+ nl_handle_destroy(handle);
+
+ return retval;
+}
+
/*
* Given an interface name (e.g., eth0), return the MAC address in human
* readable format (e.g., 00:11:52:12:D9:A0). Return NULL for no match.
diff --git a/isys/iface.h b/isys/iface.h
index 16257bc89..f67893274 100644
--- a/isys/iface.h
+++ b/isys/iface.h
@@ -118,6 +118,11 @@ char *iface_ip2str(char *, int);
*/
char *iface_mac2str(char *);
+/* Given an interface's MAC address, return the name (e.g., eth0) in human
+ * readable format. Return NULL for no match
+ */
+char *iface_mac2device(char *);
+
/*
* Convert an IPv4 CIDR prefix to a dotted-quad netmask. Return NULL on
* failure.