Skip to content
Snippets Groups Projects
Commit 11f3a4fe authored by Pierre LALET's avatar Pierre LALET
Browse files

TimeStampField.any2i() accepts a datetime object

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