Skip to content
Snippets Groups Projects
Commit 21a0cb17 authored by gpotter2's avatar gpotter2 Committed by Guillaume Valadon
Browse files

[Windows] Fixed ppi_geotag (#479)

* Fixed ppi_geotag on windows

and added tests

* More tests + static EPOCH
parent 2fbc5105
No related branches found
No related tags found
No related merge requests found
......@@ -10,11 +10,14 @@
"""
PPI-GEOLOCATION tags
"""
import struct
import struct, time
from scapy.packet import *
from scapy.fields import *
from scapy.contrib.ppi import PPIGenericFldHdr,addPPIType
# On windows, epoch is 01/02/1970 at 00:00
EPOCH = time.mktime((1970, 1, 2, 0, 0, 0, 0, 0, 0))-86400
CURR_GEOTAG_VER = 2 #Major revision of specification
PPI_GPS = 30002
......@@ -154,10 +157,15 @@ class NSCounter_Field(LEIntField):
return "%1.9f"%(y)
class UTCTimeField(IntField):
def __init__(self, name, default, epoch=time.gmtime(0), strf="%a, %d %b %Y %H:%M:%S +0000"):
__slots__ = ["epoch", "delta", "strf"]
def __init__(self, name, default, epoch=None, strf="%a, %d %b %Y %H:%M:%S +0000"):
IntField.__init__(self, name, default)
self.epoch = epoch
self.delta = time.mktime(epoch) - time.mktime(time.gmtime(0))
if epoch is None:
mk_epoch = EPOCH
else:
mk_epoch = time.mktime(epoch)
self.epoch = mk_epoch
self.delta = mk_epoch - EPOCH
self.strf = strf
def i2repr(self, pkt, x):
if x is None:
......@@ -168,11 +176,9 @@ class UTCTimeField(IntField):
class LETimeField(UTCTimeField,LEIntField):
__slots__ = ["epoch", "delta", "strf"]
def __init__(self, name, default, epoch=time.gmtime(0), strf="%a, %d %b %Y %H:%M:%S +0000"):
def __init__(self, name, default, epoch=None, strf="%a, %d %b %Y %H:%M:%S +0000"):
LEIntField.__init__(self, name, default)
self.epoch = epoch
self.delta = time.mktime(epoch) - time.mktime(time.gmtime(0))
self.strf = strf
UTCTimeField.__init__(self, name, default, epoch=epoch, strf=strf)
class SignedByteField(Field):
def __init__(self, name, default):
......
# PPI_Geotag tests
############
############
+ PPI Geotags tests
= Import PPI Geotag
from scapy.contrib.ppi_geotag import *
= Test GPS dissection
assert str(GPS()) == '2u\x08\x00\x02\x00\x08\x00\x00\x00\x00\x00'
= Test Vector dissection
assert str(Vector()) == '3u\x08\x00\x02\x00\x08\x00\x00\x00\x00\x00'
= Test Sensor dissection
assert str(Sensor()) == '4u\x08\x00\x02\x00\x08\x00\x00\x00\x00\x00'
= Test Antenna dissection
assert str(Antenna()) == '5u\x08\x00\x02\x00\x08\x00\x00\x00\x00\x00'
= Test GPSTime_Field time handling
assert GPSTime_Field("GPSTime", None).delta == 0.0
= Test UTCTimeField with time values
local_time = time.localtime()
utc_time = UTCTimeField("Test", None, epoch=local_time)
assert time.localtime(utc_time.epoch) == time.localtime()
assert time.gmtime(utc_time.delta) == time.localtime()
assert utc_time.i2repr(None, None) == (time.strftime("%a, %d %b %Y %H:%M:%S +0000", local_time) + " (" + str(int(utc_time.delta)) + ")")
= Test LETimeField with time values
local_time = time.localtime()
lme_time = LETimeField("Test", None, epoch=local_time)
assert time.localtime(lme_time.epoch) == local_time
assert time.gmtime(lme_time.delta) == local_time
assert lme_time.i2repr(None, None) == (time.strftime("%a, %d %b %Y %H:%M:%S +0000", local_time) + " (" + str(int(lme_time.delta)) + ")")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment