From 2bcc60885d8dc61d49608cf9125a2432607631b1 Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Wed, 3 Jul 2013 16:44:23 +0200 Subject: pcap: support for various linktypes Add a device_type() method to get the assigned dev->type from the kernel, and add support for automatic selection of the correct pcap file header's linktype. This needs to be integrated into the core code though. Signed-off-by: Daniel Borkmann --- dev.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'dev.c') 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; -- cgit v1.2.3-54-g00ecf