summaryrefslogtreecommitdiff
path: root/pcap_io.h
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2017-02-07 10:15:56 +0200
committerTobias Klauser <tklauser@distanz.ch>2017-02-09 10:48:24 +0100
commit71c9b1f9539f3f918269da47233dba9c07d8ec39 (patch)
tree449dbfc1221e05027480a6632d7037accfdaf73e /pcap_io.h
parent506e22f6feb39d793434b473b60c8a20ccd12995 (diff)
pcap_io: Add function to get packet timestamp
Add pcap_get_tstamp(...) function to get packet's timestamp considering different packet types & bytes order. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'pcap_io.h')
-rw-r--r--pcap_io.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/pcap_io.h b/pcap_io.h
index 4e41362..3d70b21 100644
--- a/pcap_io.h
+++ b/pcap_io.h
@@ -373,6 +373,59 @@ static inline void pcap_set_length(pcap_pkthdr_t *phdr, enum pcap_type type, u32
}
}
+static inline void pcap_get_tstamp(pcap_pkthdr_t *phdr, enum pcap_type type,
+ struct timespec *ts)
+{
+ switch (type) {
+ case DEFAULT:
+ case DEFAULT_LL:
+ ts->tv_sec = phdr->ppo.ts.tv_sec;
+ ts->tv_nsec = phdr->ppo.ts.tv_usec * 1000;
+ break;
+
+ case DEFAULT_SWAPPED:
+ case DEFAULT_LL_SWAPPED:
+ ts->tv_sec = ___constant_swab32(phdr->ppo.ts.tv_sec);
+ ts->tv_nsec = ___constant_swab32(phdr->ppo.ts.tv_usec) * 1000;;
+ break;
+
+ case NSEC:
+ case NSEC_LL:
+ ts->tv_sec = phdr->ppn.ts.tv_sec;
+ ts->tv_nsec = phdr->ppn.ts.tv_nsec / 1000;
+ break;
+
+ case NSEC_SWAPPED:
+ case NSEC_LL_SWAPPED:
+ ts->tv_sec = ___constant_swab32(phdr->ppn.ts.tv_sec);
+ ts->tv_nsec = ___constant_swab32(phdr->ppn.ts.tv_nsec);
+ break;
+
+ case KUZNETZOV:
+ ts->tv_sec = phdr->ppk.ts.tv_sec;
+ ts->tv_nsec = phdr->ppk.ts.tv_usec;
+ break;
+
+ case KUZNETZOV_SWAPPED:
+ ts->tv_sec = ___constant_swab32(phdr->ppk.ts.tv_sec);
+ ts->tv_nsec = ___constant_swab32(phdr->ppk.ts.tv_usec);
+ break;
+
+ case BORKMANN:
+ ts->tv_sec = phdr->ppb.ts.tv_sec;
+ ts->tv_nsec = phdr->ppb.ts.tv_nsec;
+ break;
+
+ case BORKMANN_SWAPPED:
+ ts->tv_sec = ___constant_swab32(phdr->ppb.ts.tv_sec);
+ ts->tv_nsec = ___constant_swab32(phdr->ppb.ts.tv_nsec);
+ break;
+
+ default:
+ bug();
+ }
+}
+
static inline u32 pcap_get_hdr_length(pcap_pkthdr_t *phdr, enum pcap_type type)
{
switch (type) {