From: Ira Weiny <ira.we...@intel.com> Getting an interface type from sysfs is easier than using an ioctl when an interface name is readily available (as is the case with netlink.)
In preparation for netlink support create a function which uses sysfs and use it instead of ioctls. Signed-off-by: Ira Weiny <ira.we...@intel.com> --- linux/acme_linux.c | 34 +++++++++++++++++++++++++++------- 1 files changed, 27 insertions(+), 7 deletions(-) diff --git a/linux/acme_linux.c b/linux/acme_linux.c index 201ff19..0bd1f75 100644 --- a/linux/acme_linux.c +++ b/linux/acme_linux.c @@ -38,6 +38,7 @@ #include <netinet/in.h> #include <sys/socket.h> #include <sys/types.h> +#include <errno.h> #include <infiniband/verbs.h> @@ -101,6 +102,31 @@ get_sgid(char *ifname, union ibv_gid *sgid) return ret; } +static int acm_if_is_ib(char *ifname) +{ + unsigned type; + char buf[128]; + FILE *f; + int ret; + + snprintf(buf, sizeof buf, "//sys//class//net//%s//type", ifname); + f = fopen(buf, "r"); + if (!f) { + printf("failed to open %s\n", buf); + return 0; + } + + if (fgets(buf, sizeof buf, f)) { + type = strtol(buf, NULL, 0); + ret = (type == ARPHRD_INFINIBAND); + } else { + ret = 0; + } + + fclose(f); + return ret; +} + static int get_devaddr(char *ifname, int *dev_index, uint8_t *port, uint16_t *pkey) { @@ -189,13 +215,7 @@ int gen_addr_ip(FILE *f) continue; } - ret = ioctl(s, SIOCGIFHWADDR, &ifr[i]); - if (ret) { - printf("failed to get hw address %d\n", ret); - continue; - } - - if (ifr[i].ifr_hwaddr.sa_family != ARPHRD_INFINIBAND) + if (!acm_if_is_ib(ifr[i].ifr_name)) continue; ret = get_devaddr(ifr[i].ifr_name, &dev_index, &port, &pkey); -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html