kbandla / dpkt

fast, simple packet creation / parsing, with definitions for the basic TCP/IP protocols
Other
1.08k stars 270 forks source link

pretty-print lists #589

Closed obormot closed 3 years ago

obormot commented 3 years ago

This is an incremental change to pretty-printing functionality that expands attributes that are lists to print pretty. E.g.

>>> eth.pprint()
Ethernet(
  dst=b'\xcc\x01\r\\\x00\x10',  # cc:01:0d:5c:00:10
  src=b'\xcc\x00\r\\\x00\x10',  # cc:00:0d:5c:00:10
  type=34887,
  labels=[
    (18, 0, 254),
    (16, 0, 255),
  ],
  mpls_labels=[
    MPLSlabel(val=18, exp=0, s=0, ttl=254),
    MPLSlabel(val=16, exp=0, s=1, ttl=255),
  ],
...
>>> tls.pprint()
TLSHandshake(
  type=1,
  length_bytes=b'\x00\x01<',  # 316
  data=TLSClientHello(
    version=771,
    ciphersuites=[
      CipherSuite(0xc02c, TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384),
      CipherSuite(0xc02b, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256),
      CipherSuite(0xc030, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384),
      CipherSuite(0xc02f, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256),
       ...
    ],
    compression_methods=(0,),
    extensions=[
      (10, b'\x00\x06\x00\x1d\x00\x17\x00\x18'),
      (11, b'\x01\x00'),
      (23, b''),
      (65281, b'\x00'),
    ],
    data=b''
coveralls commented 3 years ago

Coverage Status

Coverage increased (+4.0e-05%) to 99.815% when pulling b440d273ede571d9cfcd02add888a7d32b47170a on pretty-print-2 into 20c7c5b238a839e60fec505a062f449f5418eb55 on master.