xutils: break out promisc mode functions
[netsniff-ng.git] / tstamping.c
blob9ef1a4a13428827a364d5d7e6d83e80d7013d0e6
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"
21 #include "str.h"
23 int set_sockopt_hwtimestamp(int sock, const char *dev)
25 int timesource, ret;
26 struct hwtstamp_config hwconfig;
27 struct ifreq ifr;
29 if (!strncmp("any", dev, strlen("any")))
30 return -1;
32 memset(&hwconfig, 0, sizeof(hwconfig));
33 hwconfig.tx_type = HWTSTAMP_TX_OFF;
34 hwconfig.rx_filter = HWTSTAMP_FILTER_ALL;
36 memset(&ifr, 0, sizeof(ifr));
37 strlcpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
38 ifr.ifr_data = &hwconfig;
40 ret = ioctl(sock, SIOCSHWTSTAMP, &ifr);
41 if (ret < 0)
42 return -1;
44 timesource = SOF_TIMESTAMPING_RAW_HARDWARE;
46 return setsockopt(sock, SOL_PACKET, PACKET_TIMESTAMP, &timesource,
47 sizeof(timesource));
49 #else
50 int set_sockopt_hwtimestamp(int sock, const char *dev)
52 return -1;
54 #endif