pcap_io: Fix compiler warning
[netsniff-ng.git] / tstamping.c
blob860b7a0b28386c0896f8a9f60e11ef9afe4a5e7d
1 #include <string.h>
2 #include <sys/ioctl.h>
3 #include <sys/types.h>
4 #include <sys/socket.h>
5 #include <linux/sockios.h>
6 #include <linux/net_tstamp.h>
7 #include <linux/if_packet.h>
8 #include <linux/if.h>
10 #include "str.h"
11 #include "tstamping.h"
13 int set_sockopt_hwtimestamp(int sock, const char *dev)
15 int timesource, ret;
16 struct hwtstamp_config hwconfig;
17 struct ifreq ifr;
19 if (!strncmp("any", dev, strlen("any")))
20 return -1;
22 memset(&hwconfig, 0, sizeof(hwconfig));
23 hwconfig.tx_type = HWTSTAMP_TX_OFF;
24 hwconfig.rx_filter = HWTSTAMP_FILTER_ALL;
26 memset(&ifr, 0, sizeof(ifr));
27 strlcpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
28 ifr.ifr_data = &hwconfig;
30 ret = ioctl(sock, SIOCSHWTSTAMP, &ifr);
31 if (ret < 0)
32 return -1;
34 timesource = SOF_TIMESTAMPING_RAW_HARDWARE;
36 return setsockopt(sock, SOL_PACKET, PACKET_TIMESTAMP, &timesource,
37 sizeof(timesource));