On 2016-08-12 at 23:09:28 +0200, Vadim Kochan <vadi...@gmail.com> wrote:
> Move hw timestamp enable/disable code to sock.c as
> it is a socket related functionality, and it makes
> have less files in source tree.
> 
> Move tstamping related includes under HAVE_TSTAMPING config
> to compile them only if hw timestamping is suported.
> 
> Signed-off-by: Vadim Kochan <vadi...@gmail.com>
> ---
>  netsniff-ng.c        |  1 -
>  netsniff-ng/Makefile |  3 ---
>  sock.c               | 39 +++++++++++++++++++++++++++++++++++++++
>  sock.h               |  1 +
>  tstamping.c          | 38 --------------------------------------
>  tstamping.h          | 15 ---------------
>  6 files changed, 40 insertions(+), 57 deletions(-)
>  delete mode 100644 tstamping.c
>  delete mode 100644 tstamping.h
> 
> diff --git a/netsniff-ng.c b/netsniff-ng.c
> index ce37e10..ec060f8 100644
> --- a/netsniff-ng.c
> +++ b/netsniff-ng.c
> @@ -44,7 +44,6 @@
>  #include "lockme.h"
>  #include "tprintf.h"
>  #include "timer.h"
> -#include "tstamping.h"
>  #include "dissector.h"
>  #include "xmalloc.h"
>  
> diff --git a/netsniff-ng/Makefile b/netsniff-ng/Makefile
> index d1d8a85..c6a531f 100644
> --- a/netsniff-ng/Makefile
> +++ b/netsniff-ng/Makefile
> @@ -74,9 +74,6 @@ endif
>  ifeq ($(CONFIG_GEOIP), 1)
>  netsniff-ng-objs +=  geoip.o
>  endif
> -ifeq ($(CONFIG_HWTSTAMP), 1)
> -netsniff-ng-objs +=  tstamping.o
> -endif
>  ifeq ($(CONFIG_LIBNL), 1)
>  netsniff-ng-objs +=  mac80211.o \
>                       proto_nlmsg.o
> diff --git a/sock.c b/sock.c
> index a84796c..a4ec434 100644
> --- a/sock.c
> +++ b/sock.c
> @@ -1,7 +1,15 @@
> +#include "config.h"
> +
>  #include <sys/types.h>
>  #include <sys/socket.h>
>  #include <fcntl.h>
>  #include <arpa/inet.h>
> +#ifdef HAVE_HARDWARE_TIMESTAMPING
> +#include <linux/if.h>
> +#include <sys/ioctl.h>
> +#include <linux/sockios.h>
> +#include <linux/net_tstamp.h>
> +#endif
>  #include <linux/if_ether.h>
>  #include <linux/tcp.h>
>  
> @@ -196,3 +204,34 @@ void reset_system_socket_memory(int *vals, size_t len)
>       set_system_socket_mem(sock_wmem_max, vals[2]);
>       set_system_socket_mem(sock_wmem_def, vals[3]);
>  }
> +
> +int set_sockopt_hwtimestamp(int sock, const char *dev)
> +{
> +#ifdef HAVE_HARDWARE_TIMESTAMPING
> +     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, &timesource,
> +                       sizeof(timesource));
> +#else
> +     return -1;
> +#endif
> +}

Please add the #ifdef around the entire function and keep the static
inline function returning -1 for !HAVE_HARDWARE_TIMESTAMPING in sock.h

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to