summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--netsniff-ng.c2
-rw-r--r--netsniff-ng/Makefile1
-rw-r--r--ring.h35
-rw-r--r--tstamping.c53
4 files changed, 56 insertions, 35 deletions
diff --git a/netsniff-ng.c b/netsniff-ng.c
index 2391d39..b4a239e 100644
--- a/netsniff-ng.c
+++ b/netsniff-ng.c
@@ -37,6 +37,8 @@
#include "dissector.h"
#include "xmalloc.h"
+extern int set_sockopt_hwtimestamp(int sock, const char *dev);
+
enum dump_mode {
DUMP_INTERVAL_TIME,
DUMP_INTERVAL_SIZE,
diff --git a/netsniff-ng/Makefile b/netsniff-ng/Makefile
index 46b885d..b50778f 100644
--- a/netsniff-ng/Makefile
+++ b/netsniff-ng/Makefile
@@ -45,6 +45,7 @@ netsniff-ng-objs = dissector.o \
ring_rx.o \
ring_tx.o \
tprintf.o \
+ tstamping.o \
geoip.o \
mac80211.o \
netsniff-ng.o
diff --git a/ring.h b/ring.h
index e74661c..dea1b6c 100644
--- a/ring.h
+++ b/ring.h
@@ -131,39 +131,4 @@ static inline void set_sockopt_tpacket(int sock)
panic("Cannot set tpacketv2!\n");
}
-#ifdef __WITH_HARDWARE_TIMESTAMPING
-# include <linux/net_tstamp.h>
-
-static inline 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));
-}
-#else
-static inline int set_sockopt_hwtimestamp(int sock, const char *dev)
-{
- return -1;
-}
-#endif
#endif /* RING_H */
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, &timesource,
+ sizeof(timesource));
+}
+#else
+int set_sockopt_hwtimestamp(int sock, const char *dev)
+{
+ return -1;
+}
+#endif