diff options
author | Daniel Borkmann <dborkman@redhat.com> | 2013-05-13 12:24:34 +0200 |
---|---|---|
committer | Daniel Borkmann <dborkman@redhat.com> | 2013-05-13 12:24:34 +0200 |
commit | c59245ddcc0541edca71769b3153bc13580a5bbb (patch) | |
tree | 88df6ec5111eff73e7201347b8aa77c67ccd0019 /tstamping.c | |
parent | bf43e1993c7037ea9f23bf0cac4ec7de0e3b1ca8 (diff) |
ring: break out timestamping since not directly related
Break out the timestamping part of the ring.h file, since it's not
directly related to the {t,r}x_ring. Also inlining doesn't make
sense here.
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Diffstat (limited to 'tstamping.c')
-rw-r--r-- | tstamping.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tstamping.c b/tstamping.c new file mode 100644 index 0000000..4de455d --- /dev/null +++ b/tstamping.c @@ -0,0 +1,53 @@ +/* + * netsniff-ng - the packet sniffing beast + * Copyright 2009, 2010 Daniel Borkmann. + * Subject to the GPL, version 2. + */ + +extern int set_sockopt_hwtimestamp(int sock, const char *dev); + +#ifdef __WITH_HARDWARE_TIMESTAMPING +#include <string.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <linux/sockios.h> +#include <linux/net_tstamp.h> +#include <linux/net_tstamp.h> +#include <linux/if_packet.h> +#include <linux/if.h> + +#include "xutils.h" + +int set_sockopt_hwtimestamp(int sock, const char *dev) +{ + int timesource, ret; + struct hwtstamp_config hwconfig; + struct ifreq ifr; + + if (!strncmp("any", dev, strlen("any"))) + return -1; + + memset(&hwconfig, 0, sizeof(hwconfig)); + hwconfig.tx_type = HWTSTAMP_TX_OFF; + hwconfig.rx_filter = HWTSTAMP_FILTER_ALL; + + memset(&ifr, 0, sizeof(ifr)); + strlcpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); + ifr.ifr_data = &hwconfig; + + ret = ioctl(sock, SIOCSHWTSTAMP, &ifr); + if (ret < 0) + return -1; + + timesource = SOF_TIMESTAMPING_RAW_HARDWARE; + + return setsockopt(sock, SOL_PACKET, PACKET_TIMESTAMP, ×ource, + sizeof(timesource)); +} +#else +int set_sockopt_hwtimestamp(int sock, const char *dev) +{ + return -1; +} +#endif |