summaryrefslogtreecommitdiff
path: root/dev.c
diff options
context:
space:
mode:
Diffstat (limited to 'dev.c')
-rw-r--r--dev.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/dev.c b/dev.c
index 3e2e7af..f109a61 100644
--- a/dev.c
+++ b/dev.c
@@ -34,6 +34,30 @@ int device_ifindex(const char *ifname)
return index;
}
+int device_type(const char *ifname)
+{
+ int ret, sock, type;
+ struct ifreq ifr;
+
+ if (!strncmp("any", ifname, strlen("any")))
+ return 0;
+
+ sock = af_socket(AF_INET);
+
+ memset(&ifr, 0, sizeof(ifr));
+ strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
+
+ ret = ioctl(sock, SIOCGIFHWADDR, &ifr);
+ if (unlikely(ret))
+ panic("Cannot get iftype from device!\n");
+
+ /* dev->type */
+ type = ifr.ifr_hwaddr.sa_family;
+ close(sock);
+
+ return type;
+}
+
static int __device_address6(const char *ifname, struct sockaddr_storage *ss)
{
int ret, family, found = -EINVAL;