wltrace.utils module

Various utilitis for packet trace parsing.

wltrace.utils.align_up(offset, align)[source]

Align offset up to align boundary.

Parameters:
  • offset (int) – value to be aligned.
  • align (int) – alignment boundary.
Returns:

aligned offset.

Return type:

int

>>> align_up(3, 2)
4
>>> align_up(3, 1)
3
wltrace.utils.bin_to_mac(bin, size=6)[source]

Convert 6 bytes into a MAC string.

Parameters:bin (str) – hex string of lenth 6.
Returns:String representation of the MAC address in lower case.
Return type:str
Raises:Exception – if len(bin) is not 6.
wltrace.utils.calc_padding(fmt, align)[source]

Calculate how many padding bytes needed for fmt to be aligned to align.

Parameters:
  • fmt (str) – struct format.
  • align (int) – alignment (2, 4, 8, etc.)
Returns:

padding format (e.g., various number of ‘x’).

Return type:

str

>>> calc_padding('b', 2)
'x'
>>> calc_padding('b', 3)
'xx'
wltrace.utils.packet_gap(first, second)[source]
wltrace.utils.pairwise(it)[source]
wltrace.utils.win_ts(high, low)[source]

Convert Windows timestamp to Unix timestamp.

Windows timestamp is a 64-bit integer, the value of which is the number of 100 ns intervals from 1/1/1601-UTC.

Parameters:
  • high (int) – high 32 bits of windows timestamp.
  • low (int) – low 32 bits of windows timestamp.
Returns:

Python timestamp (datetime.datetime object).

wltrace.utils.win_ts_to_unix_epoch(high, low)[source]

Convert Windows timestamp to POSIX timestamp.

See https://goo.gl/VVX0nk

Parameters:
  • high (int) – high 32 bits of windows timestamp.
  • low (int) – low 32 bits of windows timestamp.
Returns:

float