diff options
author | Daniel Borkmann <dborkman@redhat.com> | 2013-07-03 16:44:23 +0200 |
---|---|---|
committer | Daniel Borkmann <dborkman@redhat.com> | 2013-07-03 16:44:23 +0200 |
commit | 2bcc60885d8dc61d49608cf9125a2432607631b1 (patch) | |
tree | a306cddd10d481b630a621d93a0de88a5cb39448 /dev.c | |
parent | cdafc50c08c2daecd96c84c24faf51248b77b6fb (diff) |
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 <dborkman@redhat.com>
Diffstat (limited to 'dev.c')
-rw-r--r-- | dev.c | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -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; |