diff options
-rw-r--r-- | dev.c | 25 | ||||
-rw-r--r-- | dev.h | 1 |
2 files changed, 26 insertions, 0 deletions
@@ -124,6 +124,31 @@ int device_address(const char *ifname, int af, struct sockaddr_storage *ss) return ret; } +int device_hw_address(const char *ifname, uint8_t *addr, size_t len) +{ + int ret, sock; + struct ifreq ifr; + + if (!addr) + return -EINVAL; + if (len < IFHWADDRLEN) + return -ENOSPC; + if (!strncmp("any", ifname, strlen("any"))) + return -EINVAL; + + sock = af_socket(AF_INET); + + memset(&ifr, 0, sizeof(ifr)); + strlcpy(ifr.ifr_name, ifname, IFNAMSIZ); + + ret = ioctl(sock, SIOCGIFHWADDR, &ifr); + if (!ret) + memcpy(addr, &ifr.ifr_hwaddr.sa_data[0], IFHWADDRLEN); + + close(sock); + return ret; +} + size_t device_mtu(const char *ifname) { size_t mtu = 0; @@ -7,6 +7,7 @@ extern size_t device_mtu(const char *ifname); extern int device_address(const char *ifname, int af, struct sockaddr_storage *ss); extern int __device_ifindex(const char *ifname); +extern int device_hw_address(const char *ifname, uint8_t *addr, size_t len); extern int device_ifindex(const char *ifname); extern int device_type(const char *ifname); extern short device_get_flags(const char *ifname); |