#!/usr/bin/env python
# Copyright (c) 2012, Neville-Neil Consulting
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# Neither the name of Neville-Neil Consulting nor the names of its 
# contributors may be used to endorse or promote products derived from 
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Author: George V. Neville-Neil
#
# Description: Script displays all the times found in various PTP packets.

from pcs.packets.ptp import *
from pcs.packets.ptp_common import Common
from pcs.packets.ipv4 import ipv4
from pcs.packets.udpv4 import udpv4
import pcs

def main():

    from optparse import OptionParser

    parser = OptionParser()
    parser.add_option("-f", "--file",
                      dest="file", default=None,
                      help="File to read from.")

    parser.add_option("-n", "--natural",
                      dest="human", default=False,
                      help="human readable time.")

    (options, args) = parser.parse_args()

    file = pcs.PcapConnector(options.file)

    packet = file.readpkt()

    while(packet != None):
        if packet.data == None:
            continue
        if packet.data.data == None:
            continue
        if packet.data.data.data != None:
            print packet.data.data.data
        if packet.data.data.data.data != None:
            print packet.data.data.data.data
        packet = file.readpkt()


if __name__ == "__main__":
    main()

@@ -1824,16 +1824,33 @@
 rt pcs%0A%0A
+import datetime%0A%0A
 def main
@@ -2099,16 +2099,59 @@
 tural%22,%0A
+                      action=%22store_true%22,%0A
         
@@ -2170,21 +2170,23 @@
   dest=%22
-human
+natural
 %22, defau
@@ -2493,32 +2493,32 @@
        continue%0A
-
         if packe
@@ -2535,32 +2535,385 @@
 a.data != None:%0A
+            if (options.natural == True):%0A                ts = datetime.datetime.fromtimestamp(packet.data.data.timestamp)%0A                ms = ts.microsecond / 1000%0A                msecond = ts.strftime(%22%25H:%25M:%25S%22)%0A                msecond += (%22.%25d%22) %25 ms%0A                print msecond%0A            else:%0A                print packet.data.data.timestamp%0A
             prin

Add natural, i.e. human, timestamps to the output. We can't use -h with option parser as it's reserved to the help.