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
+}
diff --git a/sock.h b/sock.h
index 8f68d42..bac27ac 100644
--- a/sock.h
+++ b/sock.h
@@ -15,5 +15,6 @@ extern int set_ipv6_only(int fd);
 extern void set_mtu_disc_dont(int fd);
 extern void set_system_socket_memory(int *vals, size_t len);
 extern void reset_system_socket_memory(int *vals, size_t len);
+extern int set_sockopt_hwtimestamp(int sock, const char *dev);
 
 #endif /* SOCK_H */
diff --git a/tstamping.c b/tstamping.c
deleted file mode 100644
index 860b7a0..0000000
--- a/tstamping.c
+++ /dev/null
@@ -1,38 +0,0 @@
-#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/if_packet.h>
-#include <linux/if.h>
-
-#include "str.h"
-#include "tstamping.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, &timesource,
-                         sizeof(timesource));
-}
diff --git a/tstamping.h b/tstamping.h
deleted file mode 100644
index ccc642e..0000000
--- a/tstamping.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef TSTAMPING_H
-#define TSTAMPING_H
-
-#include "config.h"
-
-#ifdef HAVE_HARDWARE_TIMESTAMPING
-extern int set_sockopt_hwtimestamp(int sock, const char *dev);
-#else
-static inline int set_sockopt_hwtimestamp(int sock, const char *dev)
-{
-       return -1;
-}
-#endif
-
-#endif /* TSTAMPING_H */
-- 
2.9.2

-- 
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