netsniff-ng: Add __maybe_unused attribute to timer functions
[netsniff-ng.git] / tstamping.c
blob4de455df74e08727c764847c24b6fc46ec510f8b
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009, 2010 Daniel Borkmann.
4 * Subject to the GPL, version 2.
5 */
7 extern int set_sockopt_hwtimestamp(int sock, const char *dev);
9 #ifdef __WITH_HARDWARE_TIMESTAMPING
10 #include <string.h>
11 #include <sys/ioctl.h>
12 #include <sys/types.h>
13 #include <sys/socket.h>
14 #include <linux/sockios.h>
15 #include <linux/net_tstamp.h>
16 #include <linux/net_tstamp.h>
17 #include <linux/if_packet.h>
18 #include <linux/if.h>
20 #include "xutils.h"
22 int set_sockopt_hwtimestamp(int sock, const char *dev)
24 int timesource, ret;
25 struct hwtstamp_config hwconfig;
26 struct ifreq ifr;
28 if (!strncmp("any", dev, strlen("any")))
29 return -1;
31 memset(&hwconfig, 0, sizeof(hwconfig));
32 hwconfig.tx_type = HWTSTAMP_TX_OFF;
33 hwconfig.rx_filter = HWTSTAMP_FILTER_ALL;
35 memset(&ifr, 0, sizeof(ifr));
36 strlcpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
37 ifr.ifr_data = &hwconfig;
39 ret = ioctl(sock, SIOCSHWTSTAMP, &ifr);
40 if (ret < 0)
41 return -1;
43 timesource = SOF_TIMESTAMPING_RAW_HARDWARE;
45 return setsockopt(sock, SOL_PACKET, PACKET_TIMESTAMP, &timesource,
46 sizeof(timesource));
48 #else
49 int set_sockopt_hwtimestamp(int sock, const char *dev)
51 return -1;
53 #endif