Bugs in TimeStampField(), and an appeal for an API change...
William McVey <wam <at> cisco.com>
2008-07-25 21:31:26 GMT
Related to the bug I filed at http://trac.secdev.org/scapy/ticket/119 ,
I have discovered that TimeStampField has some serious problems. The
following three issues have been identified so far:
1. There are possible values that are returned from getfield() that
are not handled addfield() method (thus raising exception
whenever build(), str(), wrpcap(), etc are called on the
packet). A good example of this is that 'None' (odly enough,
which is returned as the string "None" and not the value None.
2. Inconsistent handling of time zone information between getfield
and addfield occurs. In particular, getfield() calls gmtime
(which normalizes to UTC and always sets daylight savings to 0 )
and addfield() utilizes mktime() (which is relative to local
time zone)
3. The getfield() method ignores fractional seconds from the read
in data. This means, any field value that gets handled by
TimeStampField truncates the time resolution to a full second
and that the packet data that gets written out to a pcap file
may *NOT* be the packet data that was actually sent.
I set about to write a patch for these issues and the first 2 bugs were
pretty easily fixed. Fixing the 3rd one became problematic though, since
the dissected python value returned from a TimeStampField is a string
containing a date stamp of the format "%a, %d %b %Y %H:%M:%S +0000"
(e.g. 'Fri, 25 Jul 2008 17:11:16 +0000'). When the packet goes to get
written, this string is fed to time.strptime() (which doesn't have a
format field for fractional seconds) to get the seconds since epoch to
convert into binary. This conversion of 64 bit binary field into a
string and back again using the time module is a very lossey process
(effectively zeroing out least significant 32 bits of the field).
Ideally, I'd like to change the behavior of the TimeStampField to return
(and accept) a datetime.datetime() object which supports microsecond
resolution. This is a pretty major API change though. I'm not even 100%
it's feasible for the dissector to return a datetime.datetime object (I
don't see why it wouldn't be, but it's been ages since I tinkered with
the internals of scapy). Anyway, if returning the datetime object itself
is too big of a change, then I'd like to at least change the date string
format from the current format (which doesn't handle fractional seconds)
to the ISO 8601 format (e.g. '2008-07-25T20:48:26.076754'). This way,
the fractional seconds could at least be represented within the return
value. As things are now, scapy is severely limited when it deals with
NTP.
-- William
---------------------------------------------------------------------
To unsubscribe, send a mail to scapy.ml-unsubscribe <at> secdev.org