GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

PcapLogger   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 26
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A encodeData() 0 11 1
A onOpen() 0 13 1
1
from struct import Struct
2
import time
3
import math
4
5
from libAnt.loggers.logger import Logger
6
7
class PcapLogger(Logger):
8
    def onOpen(self):
9
        # write pcap global header
10
        magic_number = b'\xD4\xC3\xB2\xA1'
11
        version_major = 2
12
        version_minor = 4
13
        thiszone = b'\x00\x00\x00\x00'
14
        sigfigs = b'\x00\x00\x00\x00'
15
        snaplen = b'\xFF\x00\x00\x00'
16
        network = b'\x01\x00\x00\x00'
17
        pcap_global_header = Struct('<4shh4s4s4s4s')
18
        self._log.write(
19
            pcap_global_header.pack(magic_number, version_major, version_minor, thiszone, sigfigs,
20
                                    snaplen, network))
21
22
    def encodeData(self, data):
23
        timestamp = time.time()
24
        frac, whole = math.modf(timestamp)
25
26
        ts_sec = int(whole).to_bytes(4, byteorder='little')
27
        ts_usec = int(frac * 1000 * 1000).to_bytes(4, byteorder='little')
28
        incl_len = len(data)
29
        orig_len = incl_len
30
31
        pcap_packet_header = Struct('<4s4sll').pack(ts_sec, ts_usec, incl_len, orig_len)
32
        return pcap_packet_header + data