Skip to content
Snippets Groups Projects
Commit ac2d77ea authored by Guillaume Valadon's avatar Guillaume Valadon
Browse files

Merge pull request #137 from p-l-/fix-ntp

Fix NTP TimeStampField.any2i()
parents 9fce9b96 11f3a4fe
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ NTP (Network Time Protocol). ...@@ -8,6 +8,7 @@ NTP (Network Time Protocol).
""" """
import time import time
import datetime
from scapy.packet import * from scapy.packet import *
from scapy.fields import * from scapy.fields import *
from scapy.layers.inet import UDP from scapy.layers.inet import UDP
...@@ -29,9 +30,11 @@ class TimeStampField(FixedPointField): ...@@ -29,9 +30,11 @@ class TimeStampField(FixedPointField):
return time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(val-_NTP_BASETIME)) return time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(val-_NTP_BASETIME))
def any2i(self, pkt, val): def any2i(self, pkt, val):
if type(val) is str: if isinstance(val, basestring):
return int(time.mktime(time.strptime(val))) + _NTP_BASETIME + 3600 # XXX val = int(time.mktime(time.strptime(val))) + _NTP_BASETIME
return FixedPointField.any2i(self,pkt,val) elif isinstance(val, datetime.datetime):
val = int(val.strftime("%s")) + _NTP_BASETIME
return FixedPointField.any2i(self, pkt, val)
def i2m(self, pkt, val): def i2m(self, pkt, val):
if val is None: if val is None:
......
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