repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_documentation_string
stringlengths 1
47.2k
| func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|
JarryShaw/PyPCAPKit | src/reassembly/ip.py | IP_Reassembly.reassembly | def reassembly(self, info):
"""Reassembly procedure.
Positional arguments:
* info -- Info, info dict of packets to be reassembled
"""
BUFID = info.bufid # Buffer Identifier
FO = info.fo # Fragment Offset
IHL = info.ihl # Internet Header Length
MF = info.mf # More Fragments flag
TL = info.tl # Total Length
# when non-fragmented (possibly discarded) packet received
if not FO and not MF:
if BUFID in self._buffer:
self._dtgram += self.submit(self._buffer[BUFID])
del self._buffer[BUFID]
return
# initialise buffer with BUFID
if BUFID not in self._buffer:
self._buffer[BUFID] = dict(
TDL=0, # Total Data Length
RCVBT=bytearray(8191), # Fragment Received Bit Table
index=list(), # index record
header=bytearray(), # header buffer
datagram=bytearray(65535), # data buffer
)
# append packet index
self._buffer[BUFID]['index'].append(info.num)
# put data into data buffer
start = FO
stop = TL - IHL + FO
self._buffer[BUFID]['datagram'][start:stop] = info.payload
# set RCVBT bits (in 8 octets)
start = FO // 8
stop = FO // 8 + (TL - IHL + 7) // 8
self._buffer[BUFID]['RCVBT'][start:stop] = b'\x01' * (stop - start + 1)
# get total data length (header excludes)
if not MF:
TDL = TL - IHL + FO
# put header into header buffer
if not FO:
self._buffer[BUFID]['header'] = info.header
# when datagram is reassembled in whole
start = 0
stop = (TDL + 7) // 8
if TDL and all(self._buffer[BUFID]['RCVBT'][start:stop]):
self._dtgram += self.submit(self._buffer[BUFID], checked=True)
del self._buffer[BUFID] | python | def reassembly(self, info):
"""Reassembly procedure.
Positional arguments:
* info -- Info, info dict of packets to be reassembled
"""
BUFID = info.bufid # Buffer Identifier
FO = info.fo # Fragment Offset
IHL = info.ihl # Internet Header Length
MF = info.mf # More Fragments flag
TL = info.tl # Total Length
# when non-fragmented (possibly discarded) packet received
if not FO and not MF:
if BUFID in self._buffer:
self._dtgram += self.submit(self._buffer[BUFID])
del self._buffer[BUFID]
return
# initialise buffer with BUFID
if BUFID not in self._buffer:
self._buffer[BUFID] = dict(
TDL=0, # Total Data Length
RCVBT=bytearray(8191), # Fragment Received Bit Table
index=list(), # index record
header=bytearray(), # header buffer
datagram=bytearray(65535), # data buffer
)
# append packet index
self._buffer[BUFID]['index'].append(info.num)
# put data into data buffer
start = FO
stop = TL - IHL + FO
self._buffer[BUFID]['datagram'][start:stop] = info.payload
# set RCVBT bits (in 8 octets)
start = FO // 8
stop = FO // 8 + (TL - IHL + 7) // 8
self._buffer[BUFID]['RCVBT'][start:stop] = b'\x01' * (stop - start + 1)
# get total data length (header excludes)
if not MF:
TDL = TL - IHL + FO
# put header into header buffer
if not FO:
self._buffer[BUFID]['header'] = info.header
# when datagram is reassembled in whole
start = 0
stop = (TDL + 7) // 8
if TDL and all(self._buffer[BUFID]['RCVBT'][start:stop]):
self._dtgram += self.submit(self._buffer[BUFID], checked=True)
del self._buffer[BUFID] | Reassembly procedure.
Positional arguments:
* info -- Info, info dict of packets to be reassembled | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/reassembly/ip.py#L109-L165 |
JarryShaw/PyPCAPKit | src/reassembly/ip.py | IP_Reassembly.submit | def submit(self, buf, *, checked=False):
"""Submit reassembled payload.
Positional arguments:
* buf -- dict, buffer dict of reassembled packets
Keyword arguments:
* bufid -- tuple, buffer identifier
Returns:
* list -- reassembled packets
"""
TDL = buf['TDL']
RCVBT = buf['RCVBT']
index = buf['index']
header = buf['header']
datagram = buf['datagram']
start = 0
stop = (TDL + 7) // 8
flag = checked or (TDL and all(RCVBT[start:stop]))
# if datagram is not implemented
if not flag and self._strflg:
data = list()
byte = bytearray()
# extract received payload
for (bctr, bit) in enumerate(RCVBT):
if bit: # received bit
this = bctr * 8
that = this + 8
byte += datagram[this:that]
else: # missing bit
if byte: # strip empty payload
data.append(bytes(byte))
byte = bytearray()
# strip empty packets
if data or header:
packet = Info(
NotImplemented=True,
index=tuple(index),
header=header or None,
payload=tuple(data) or None,
)
# if datagram is reassembled in whole
else:
payload = datagram[:TDL]
packet = Info(
NotImplemented=False,
index=tuple(index),
packet=(bytes(header) + bytes(payload)) or None,
)
return [packet] | python | def submit(self, buf, *, checked=False):
"""Submit reassembled payload.
Positional arguments:
* buf -- dict, buffer dict of reassembled packets
Keyword arguments:
* bufid -- tuple, buffer identifier
Returns:
* list -- reassembled packets
"""
TDL = buf['TDL']
RCVBT = buf['RCVBT']
index = buf['index']
header = buf['header']
datagram = buf['datagram']
start = 0
stop = (TDL + 7) // 8
flag = checked or (TDL and all(RCVBT[start:stop]))
# if datagram is not implemented
if not flag and self._strflg:
data = list()
byte = bytearray()
# extract received payload
for (bctr, bit) in enumerate(RCVBT):
if bit: # received bit
this = bctr * 8
that = this + 8
byte += datagram[this:that]
else: # missing bit
if byte: # strip empty payload
data.append(bytes(byte))
byte = bytearray()
# strip empty packets
if data or header:
packet = Info(
NotImplemented=True,
index=tuple(index),
header=header or None,
payload=tuple(data) or None,
)
# if datagram is reassembled in whole
else:
payload = datagram[:TDL]
packet = Info(
NotImplemented=False,
index=tuple(index),
packet=(bytes(header) + bytes(payload)) or None,
)
return [packet] | Submit reassembled payload.
Positional arguments:
* buf -- dict, buffer dict of reassembled packets
Keyword arguments:
* bufid -- tuple, buffer identifier
Returns:
* list -- reassembled packets | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/reassembly/ip.py#L167-L219 |
JarryShaw/PyPCAPKit | src/protocols/internet/ipv6.py | IPv6.read_ipv6 | def read_ipv6(self, length):
"""Read Internet Protocol version 6 (IPv6).
Structure of IPv6 header [RFC 2460]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version| Traffic Class | Flow Label |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Payload Length | Next Header | Hop Limit |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ +
| |
+ Source Address +
| |
+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ +
| |
+ Destination Address +
| |
+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 ip.version Version (6)
0 4 ip.class Traffic Class
1 12 ip.label Flow Label
4 32 ip.payload Payload Length (header excludes)
6 48 ip.next Next Header
7 56 ip.limit Hop Limit
8 64 ip.src Source Address
24 192 ip.dst Destination Address
"""
if length is None:
length = len(self)
_htet = self._read_ip_hextet()
_plen = self._read_unpack(2)
_next = self._read_protos(1)
_hlmt = self._read_unpack(1)
_srca = self._read_ip_addr()
_dsta = self._read_ip_addr()
ipv6 = dict(
version=_htet[0],
tclass=_htet[1],
label=_htet[2],
payload=_plen,
next=_next,
limit=_hlmt,
src=_srca,
dst=_dsta,
)
hdr_len = 40
raw_len = ipv6['payload']
ipv6['packet'] = self._read_packet(header=hdr_len, payload=raw_len)
return self._decode_next_layer(ipv6, _next, raw_len) | python | def read_ipv6(self, length):
"""Read Internet Protocol version 6 (IPv6).
Structure of IPv6 header [RFC 2460]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version| Traffic Class | Flow Label |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Payload Length | Next Header | Hop Limit |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ +
| |
+ Source Address +
| |
+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ +
| |
+ Destination Address +
| |
+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 ip.version Version (6)
0 4 ip.class Traffic Class
1 12 ip.label Flow Label
4 32 ip.payload Payload Length (header excludes)
6 48 ip.next Next Header
7 56 ip.limit Hop Limit
8 64 ip.src Source Address
24 192 ip.dst Destination Address
"""
if length is None:
length = len(self)
_htet = self._read_ip_hextet()
_plen = self._read_unpack(2)
_next = self._read_protos(1)
_hlmt = self._read_unpack(1)
_srca = self._read_ip_addr()
_dsta = self._read_ip_addr()
ipv6 = dict(
version=_htet[0],
tclass=_htet[1],
label=_htet[2],
payload=_plen,
next=_next,
limit=_hlmt,
src=_srca,
dst=_dsta,
)
hdr_len = 40
raw_len = ipv6['payload']
ipv6['packet'] = self._read_packet(header=hdr_len, payload=raw_len)
return self._decode_next_layer(ipv6, _next, raw_len) | Read Internet Protocol version 6 (IPv6).
Structure of IPv6 header [RFC 2460]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version| Traffic Class | Flow Label |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Payload Length | Next Header | Hop Limit |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ +
| |
+ Source Address +
| |
+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ +
| |
+ Destination Address +
| |
+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 ip.version Version (6)
0 4 ip.class Traffic Class
1 12 ip.label Flow Label
4 32 ip.payload Payload Length (header excludes)
6 48 ip.next Next Header
7 56 ip.limit Hop Limit
8 64 ip.src Source Address
24 192 ip.dst Destination Address | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/ipv6.py#L102-L167 |
JarryShaw/PyPCAPKit | src/protocols/internet/ipv6.py | IPv6._read_ip_hextet | def _read_ip_hextet(self):
"""Read first four hextets of IPv6."""
_htet = self._read_fileng(4).hex()
_vers = _htet[0] # version number (6)
_tcls = int(_htet[0:2], base=16) # traffic class
_flow = int(_htet[2:], base=16) # flow label
return (_vers, _tcls, _flow) | python | def _read_ip_hextet(self):
"""Read first four hextets of IPv6."""
_htet = self._read_fileng(4).hex()
_vers = _htet[0] # version number (6)
_tcls = int(_htet[0:2], base=16) # traffic class
_flow = int(_htet[2:], base=16) # flow label
return (_vers, _tcls, _flow) | Read first four hextets of IPv6. | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/ipv6.py#L188-L195 |
JarryShaw/PyPCAPKit | src/protocols/internet/ipv6.py | IPv6._decode_next_layer | def _decode_next_layer(self, ipv6, proto=None, length=None):
"""Decode next layer extractor.
Positional arguments:
* ipv6 -- dict, info buffer
* proto -- str, next layer protocol name
* length -- int, valid (not padding) length
Returns:
* dict -- current protocol with next layer extracted
"""
hdr_len = 40 # header length
raw_len = ipv6['payload'] # payload length
_protos = list() # ProtoChain buffer
# traverse if next header is an extensive header
while proto in EXT_HDR:
# keep original data after fragment header
if proto.value == 44:
ipv6['fragment'] = self._read_packet(header=hdr_len, payload=raw_len)
# # directly break when No Next Header occurs
# if proto.name == 'IPv6-NoNxt':
# proto = None
# break
# make protocol name
next_ = self._import_next_layer(proto, version=6, extension=True)
info = next_.info
name = next_.alias.lstrip('IPv6-').lower()
ipv6[name] = info
# record protocol name
# self._protos = ProtoChain(name, chain, alias)
_protos.append(next_)
proto = info.next # pylint: disable=E1101
# update header & payload length
hdr_len += info.length # pylint: disable=E1101
raw_len -= info.length # pylint: disable=E1101
# record real header & payload length (headers exclude)
ipv6['hdr_len'] = hdr_len
ipv6['raw_len'] = raw_len
# update next header
ipv6['protocol'] = proto
return super()._decode_next_layer(ipv6, proto, raw_len, ipv6_exthdr=_protos) | python | def _decode_next_layer(self, ipv6, proto=None, length=None):
"""Decode next layer extractor.
Positional arguments:
* ipv6 -- dict, info buffer
* proto -- str, next layer protocol name
* length -- int, valid (not padding) length
Returns:
* dict -- current protocol with next layer extracted
"""
hdr_len = 40 # header length
raw_len = ipv6['payload'] # payload length
_protos = list() # ProtoChain buffer
# traverse if next header is an extensive header
while proto in EXT_HDR:
# keep original data after fragment header
if proto.value == 44:
ipv6['fragment'] = self._read_packet(header=hdr_len, payload=raw_len)
# # directly break when No Next Header occurs
# if proto.name == 'IPv6-NoNxt':
# proto = None
# break
# make protocol name
next_ = self._import_next_layer(proto, version=6, extension=True)
info = next_.info
name = next_.alias.lstrip('IPv6-').lower()
ipv6[name] = info
# record protocol name
# self._protos = ProtoChain(name, chain, alias)
_protos.append(next_)
proto = info.next # pylint: disable=E1101
# update header & payload length
hdr_len += info.length # pylint: disable=E1101
raw_len -= info.length # pylint: disable=E1101
# record real header & payload length (headers exclude)
ipv6['hdr_len'] = hdr_len
ipv6['raw_len'] = raw_len
# update next header
ipv6['protocol'] = proto
return super()._decode_next_layer(ipv6, proto, raw_len, ipv6_exthdr=_protos) | Decode next layer extractor.
Positional arguments:
* ipv6 -- dict, info buffer
* proto -- str, next layer protocol name
* length -- int, valid (not padding) length
Returns:
* dict -- current protocol with next layer extracted | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/ipv6.py#L238-L286 |
JarryShaw/PyPCAPKit | src/protocols/internet/internet.py | Internet._read_protos | def _read_protos(self, size):
"""Read next layer protocol type.
Positional arguments:
* size -- int, buffer size
Returns:
* str -- next layer's protocol name
"""
_byte = self._read_unpack(size)
_prot = TP_PROTO.get(_byte)
return _prot | python | def _read_protos(self, size):
"""Read next layer protocol type.
Positional arguments:
* size -- int, buffer size
Returns:
* str -- next layer's protocol name
"""
_byte = self._read_unpack(size)
_prot = TP_PROTO.get(_byte)
return _prot | Read next layer protocol type.
Positional arguments:
* size -- int, buffer size
Returns:
* str -- next layer's protocol name | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/internet.py#L63-L75 |
JarryShaw/PyPCAPKit | src/protocols/internet/internet.py | Internet._decode_next_layer | def _decode_next_layer(self, dict_, proto=None, length=None, *, version=4, ipv6_exthdr=None):
"""Decode next layer extractor.
Positional arguments:
* dict_ -- dict, info buffer
* proto -- str, next layer protocol name
* length -- int, valid (not padding) length
Keyword Arguments:
* version -- int, IP version (4 in default)
<keyword> 4 / 6
* ext_proto -- ProtoChain, ProtoChain of IPv6 extension headers
Returns:
* dict -- current protocol with next layer extracted
"""
if self._onerror:
next_ = beholder(self._import_next_layer)(self, proto, length, version=version)
else:
next_ = self._import_next_layer(proto, length, version=version)
info, chain = next_.info, next_.protochain
# make next layer protocol name
layer = next_.alias.lower()
# proto = next_.__class__.__name__
# write info and protocol chain into dict
dict_[layer] = info
self._next = next_
if ipv6_exthdr is not None:
for proto in reversed(ipv6_exthdr):
chain = ProtoChain(proto.__class__, proto.alias, basis=chain)
self._protos = ProtoChain(self.__class__, self.alias, basis=chain)
return dict_ | python | def _decode_next_layer(self, dict_, proto=None, length=None, *, version=4, ipv6_exthdr=None):
"""Decode next layer extractor.
Positional arguments:
* dict_ -- dict, info buffer
* proto -- str, next layer protocol name
* length -- int, valid (not padding) length
Keyword Arguments:
* version -- int, IP version (4 in default)
<keyword> 4 / 6
* ext_proto -- ProtoChain, ProtoChain of IPv6 extension headers
Returns:
* dict -- current protocol with next layer extracted
"""
if self._onerror:
next_ = beholder(self._import_next_layer)(self, proto, length, version=version)
else:
next_ = self._import_next_layer(proto, length, version=version)
info, chain = next_.info, next_.protochain
# make next layer protocol name
layer = next_.alias.lower()
# proto = next_.__class__.__name__
# write info and protocol chain into dict
dict_[layer] = info
self._next = next_
if ipv6_exthdr is not None:
for proto in reversed(ipv6_exthdr):
chain = ProtoChain(proto.__class__, proto.alias, basis=chain)
self._protos = ProtoChain(self.__class__, self.alias, basis=chain)
return dict_ | Decode next layer extractor.
Positional arguments:
* dict_ -- dict, info buffer
* proto -- str, next layer protocol name
* length -- int, valid (not padding) length
Keyword Arguments:
* version -- int, IP version (4 in default)
<keyword> 4 / 6
* ext_proto -- ProtoChain, ProtoChain of IPv6 extension headers
Returns:
* dict -- current protocol with next layer extracted | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/internet.py#L77-L111 |
JarryShaw/PyPCAPKit | src/protocols/internet/internet.py | Internet._import_next_layer | def _import_next_layer(self, proto, length=None, *, version=4, extension=False):
"""Import next layer extractor.
Positional arguments:
* proto -- str, next layer protocol name
* length -- int, valid (not padding) length
Keyword Arguments:
* version -- int, IP version (4 in default)
<keyword> 4 / 6
* extension -- bool, if is extension header (False in default)
<keyword> True / False
Returns:
* bool -- flag if extraction of next layer succeeded
* Info -- info of next layer
* ProtoChain -- protocol chain of next layer
* str -- alias of next layer
Protocols:
* IPv4 -- internet layer
* IPv6 -- internet layer
* AH -- internet layer
* TCP -- transport layer
* UDP -- transport layer
"""
if length == 0:
from pcapkit.protocols.null import NoPayload as Protocol
elif self._sigterm or proto == 59:
from pcapkit.protocols.raw import Raw as Protocol
elif proto == 51:
from pcapkit.protocols.internet.ah import AH as Protocol
elif proto == 139:
from pcapkit.protocols.internet.hip import HIP as Protocol
elif proto == 0:
from pcapkit.protocols.internet.hopopt import HOPOPT as Protocol
elif proto == 44:
from pcapkit.protocols.internet.ipv6_frag import IPv6_Frag as Protocol
elif proto == 60:
from pcapkit.protocols.internet.ipv6_opts import IPv6_Opts as Protocol
elif proto == 43:
from pcapkit.protocols.internet.ipv6_route import IPv6_Route as Protocol
elif proto == 135:
from pcapkit.protocols.internet.mh import MH as Protocol
elif proto == 4:
from pcapkit.protocols.internet.ipv4 import IPv4 as Protocol
elif proto == 41:
from pcapkit.protocols.internet.ipv6 import IPv6 as Protocol
elif proto == 6:
from pcapkit.protocols.transport.tcp import TCP as Protocol
elif proto == 17:
from pcapkit.protocols.transport.udp import UDP as Protocol
else:
from pcapkit.protocols.raw import Raw as Protocol
next_ = Protocol(self._file, length, version=version, extension=extension,
error=self._onerror, layer=self._exlayer, protocol=self._exproto)
return next_ | python | def _import_next_layer(self, proto, length=None, *, version=4, extension=False):
"""Import next layer extractor.
Positional arguments:
* proto -- str, next layer protocol name
* length -- int, valid (not padding) length
Keyword Arguments:
* version -- int, IP version (4 in default)
<keyword> 4 / 6
* extension -- bool, if is extension header (False in default)
<keyword> True / False
Returns:
* bool -- flag if extraction of next layer succeeded
* Info -- info of next layer
* ProtoChain -- protocol chain of next layer
* str -- alias of next layer
Protocols:
* IPv4 -- internet layer
* IPv6 -- internet layer
* AH -- internet layer
* TCP -- transport layer
* UDP -- transport layer
"""
if length == 0:
from pcapkit.protocols.null import NoPayload as Protocol
elif self._sigterm or proto == 59:
from pcapkit.protocols.raw import Raw as Protocol
elif proto == 51:
from pcapkit.protocols.internet.ah import AH as Protocol
elif proto == 139:
from pcapkit.protocols.internet.hip import HIP as Protocol
elif proto == 0:
from pcapkit.protocols.internet.hopopt import HOPOPT as Protocol
elif proto == 44:
from pcapkit.protocols.internet.ipv6_frag import IPv6_Frag as Protocol
elif proto == 60:
from pcapkit.protocols.internet.ipv6_opts import IPv6_Opts as Protocol
elif proto == 43:
from pcapkit.protocols.internet.ipv6_route import IPv6_Route as Protocol
elif proto == 135:
from pcapkit.protocols.internet.mh import MH as Protocol
elif proto == 4:
from pcapkit.protocols.internet.ipv4 import IPv4 as Protocol
elif proto == 41:
from pcapkit.protocols.internet.ipv6 import IPv6 as Protocol
elif proto == 6:
from pcapkit.protocols.transport.tcp import TCP as Protocol
elif proto == 17:
from pcapkit.protocols.transport.udp import UDP as Protocol
else:
from pcapkit.protocols.raw import Raw as Protocol
next_ = Protocol(self._file, length, version=version, extension=extension,
error=self._onerror, layer=self._exlayer, protocol=self._exproto)
return next_ | Import next layer extractor.
Positional arguments:
* proto -- str, next layer protocol name
* length -- int, valid (not padding) length
Keyword Arguments:
* version -- int, IP version (4 in default)
<keyword> 4 / 6
* extension -- bool, if is extension header (False in default)
<keyword> True / False
Returns:
* bool -- flag if extraction of next layer succeeded
* Info -- info of next layer
* ProtoChain -- protocol chain of next layer
* str -- alias of next layer
Protocols:
* IPv4 -- internet layer
* IPv6 -- internet layer
* AH -- internet layer
* TCP -- transport layer
* UDP -- transport layer | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/internet.py#L113-L170 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP.read_hip | def read_hip(self, length, extension):
"""Read Host Identity Protocol.
Structure of HIP header [RFC 5201][RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Header | Header Length |0| Packet Type |Version| RES.|1|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Checksum | Controls |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Sender's Host Identity Tag (HIT) |
| |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Receiver's Host Identity Tag (HIT) |
| |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
/ HIP Parameters /
/ /
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hip.next Next Header
1 8 hip.length Header Length
2 16 - Reserved (0)
2 17 hip.type Packet Type
3 24 hip.version Version
3 28 - Reserved
3 31 - Reserved (1)
4 32 hip.chksum Checksum
6 48 hip.control Controls
8 64 hip.shit Sender's Host Identity Tag
24 192 hip.rhit Receiver's Host Identity Tag
40 320 hip.parameters HIP Parameters
"""
if length is None:
length = len(self)
_next = self._read_protos(1)
_hlen = self._read_unpack(1)
_type = self._read_binary(1)
if _type[0] != '0':
raise ProtocolError('HIP: invalid format')
_vers = self._read_binary(1)
if _vers[7] != '1':
raise ProtocolError('HIP: invalid format')
_csum = self._read_fileng(2)
_ctrl = self._read_binary(2)
_shit = self._read_unpack(16)
_rhit = self._read_unpack(16)
hip = dict(
next=_next,
length=(_hlen + 1) * 8,
type=_HIP_TYPES.get(int(_type[1:], base=2), 'Unassigned'),
version=int(_vers[:4], base=2),
chksum=_csum,
control=dict(
anonymous=True if int(_ctrl[15], base=2) else False,
),
shit=_shit,
rhit=_rhit,
)
_prml = _hlen - 38
if _prml:
parameters = self._read_hip_para(_prml, version=hip['version'])
hip['parameters'] = parameters[0] # tuple of parameter acronyms
hip.update(parameters[1]) # merge parameters info to buffer
length -= hip['length']
hip['packet'] = self._read_packet(header=hip['length'], payload=length)
if extension:
self._protos = None
return hip
return self._decode_next_layer(hip, _next, length) | python | def read_hip(self, length, extension):
"""Read Host Identity Protocol.
Structure of HIP header [RFC 5201][RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Header | Header Length |0| Packet Type |Version| RES.|1|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Checksum | Controls |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Sender's Host Identity Tag (HIT) |
| |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Receiver's Host Identity Tag (HIT) |
| |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
/ HIP Parameters /
/ /
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hip.next Next Header
1 8 hip.length Header Length
2 16 - Reserved (0)
2 17 hip.type Packet Type
3 24 hip.version Version
3 28 - Reserved
3 31 - Reserved (1)
4 32 hip.chksum Checksum
6 48 hip.control Controls
8 64 hip.shit Sender's Host Identity Tag
24 192 hip.rhit Receiver's Host Identity Tag
40 320 hip.parameters HIP Parameters
"""
if length is None:
length = len(self)
_next = self._read_protos(1)
_hlen = self._read_unpack(1)
_type = self._read_binary(1)
if _type[0] != '0':
raise ProtocolError('HIP: invalid format')
_vers = self._read_binary(1)
if _vers[7] != '1':
raise ProtocolError('HIP: invalid format')
_csum = self._read_fileng(2)
_ctrl = self._read_binary(2)
_shit = self._read_unpack(16)
_rhit = self._read_unpack(16)
hip = dict(
next=_next,
length=(_hlen + 1) * 8,
type=_HIP_TYPES.get(int(_type[1:], base=2), 'Unassigned'),
version=int(_vers[:4], base=2),
chksum=_csum,
control=dict(
anonymous=True if int(_ctrl[15], base=2) else False,
),
shit=_shit,
rhit=_rhit,
)
_prml = _hlen - 38
if _prml:
parameters = self._read_hip_para(_prml, version=hip['version'])
hip['parameters'] = parameters[0] # tuple of parameter acronyms
hip.update(parameters[1]) # merge parameters info to buffer
length -= hip['length']
hip['packet'] = self._read_packet(header=hip['length'], payload=length)
if extension:
self._protos = None
return hip
return self._decode_next_layer(hip, _next, length) | Read Host Identity Protocol.
Structure of HIP header [RFC 5201][RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Header | Header Length |0| Packet Type |Version| RES.|1|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Checksum | Controls |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Sender's Host Identity Tag (HIT) |
| |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Receiver's Host Identity Tag (HIT) |
| |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
/ HIP Parameters /
/ /
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hip.next Next Header
1 8 hip.length Header Length
2 16 - Reserved (0)
2 17 hip.type Packet Type
3 24 hip.version Version
3 28 - Reserved
3 31 - Reserved (1)
4 32 hip.chksum Checksum
6 48 hip.control Controls
8 64 hip.shit Sender's Host Identity Tag
24 192 hip.rhit Receiver's Host Identity Tag
40 320 hip.parameters HIP Parameters | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L138-L221 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_hip_para | def _read_hip_para(self, length, *, version):
"""Read HIP parameters.
Positional arguments:
* length -- int, length of parameters
Keyword arguments:
* version -- int, HIP version
Returns:
* dict -- extracted HIP parameters
"""
counter = 0 # length of read parameters
optkind = list() # parameter type list
options = dict() # dict of parameter data
while counter < length:
# break when eol triggered
kind = self._read_binary(2)
if not kind:
break
# get parameter type & C-bit
code = int(kind, base=2)
cbit = True if int(kind[15], base=2) else False
# get parameter length
clen = self._read_unpack(2)
plen = 11 + clen - (clen + 3) % 8
# extract parameter
dscp = _HIP_PARA.get(code, 'Unassigned')
# if 0 <= code <= 1023 or 61440 <= code <= 65535:
# desc = f'{dscp} (IETF Review)'
# elif 1024 <= code <= 32767 or 49152 <= code <= 61439:
# desc = f'{dscp} (Specification Required)'
# elif 32768 <= code <= 49151:
# desc = f'{dscp} (Reserved for Private Use)'
# else:
# raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid parameter')
data = _HIP_PROC(dscp)(self, code, cbit, clen, desc=dscp, length=plen, version=version)
# record parameter data
counter += plen
if dscp in optkind:
if isinstance(options[dscp], tuple):
options[dscp] += (Info(data),)
else:
options[dscp] = (Info(options[dscp]), Info(data))
else:
optkind.append(dscp)
options[dscp] = data
# check threshold
if counter != length:
raise ProtocolError(f'HIPv{version}: invalid format')
return tuple(optkind), options | python | def _read_hip_para(self, length, *, version):
"""Read HIP parameters.
Positional arguments:
* length -- int, length of parameters
Keyword arguments:
* version -- int, HIP version
Returns:
* dict -- extracted HIP parameters
"""
counter = 0 # length of read parameters
optkind = list() # parameter type list
options = dict() # dict of parameter data
while counter < length:
# break when eol triggered
kind = self._read_binary(2)
if not kind:
break
# get parameter type & C-bit
code = int(kind, base=2)
cbit = True if int(kind[15], base=2) else False
# get parameter length
clen = self._read_unpack(2)
plen = 11 + clen - (clen + 3) % 8
# extract parameter
dscp = _HIP_PARA.get(code, 'Unassigned')
# if 0 <= code <= 1023 or 61440 <= code <= 65535:
# desc = f'{dscp} (IETF Review)'
# elif 1024 <= code <= 32767 or 49152 <= code <= 61439:
# desc = f'{dscp} (Specification Required)'
# elif 32768 <= code <= 49151:
# desc = f'{dscp} (Reserved for Private Use)'
# else:
# raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid parameter')
data = _HIP_PROC(dscp)(self, code, cbit, clen, desc=dscp, length=plen, version=version)
# record parameter data
counter += plen
if dscp in optkind:
if isinstance(options[dscp], tuple):
options[dscp] += (Info(data),)
else:
options[dscp] = (Info(options[dscp]), Info(data))
else:
optkind.append(dscp)
options[dscp] = data
# check threshold
if counter != length:
raise ProtocolError(f'HIPv{version}: invalid format')
return tuple(optkind), options | Read HIP parameters.
Positional arguments:
* length -- int, length of parameters
Keyword arguments:
* version -- int, HIP version
Returns:
* dict -- extracted HIP parameters | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L239-L297 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_unassigned | def _read_para_unassigned(self, code, cbit, clen, *, desc, length, version):
"""Read HIP unassigned parameters.
Structure of HIP unassigned parameters [RFC 5201][RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type |C| Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
/ Contents /
/ +-+-+-+-+-+-+-+-+
| | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 para.type Parameter Type
1 15 para.critical Critical Bit
2 16 para.length Length of Contents
4 32 para.contents Contents
- - - Padding
"""
unassigned = dict(
type=desc,
critical=cbit,
length=clen,
contents=self._read_fileng(clen),
)
plen = length - clen
if plen:
self._read_fileng(plen)
return unassigned | python | def _read_para_unassigned(self, code, cbit, clen, *, desc, length, version):
"""Read HIP unassigned parameters.
Structure of HIP unassigned parameters [RFC 5201][RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type |C| Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
/ Contents /
/ +-+-+-+-+-+-+-+-+
| | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 para.type Parameter Type
1 15 para.critical Critical Bit
2 16 para.length Length of Contents
4 32 para.contents Contents
- - - Padding
"""
unassigned = dict(
type=desc,
critical=cbit,
length=clen,
contents=self._read_fileng(clen),
)
plen = length - clen
if plen:
self._read_fileng(plen)
return unassigned | Read HIP unassigned parameters.
Structure of HIP unassigned parameters [RFC 5201][RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type |C| Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
/ Contents /
/ +-+-+-+-+-+-+-+-+
| | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 para.type Parameter Type
1 15 para.critical Critical Bit
2 16 para.length Length of Contents
4 32 para.contents Contents
- - - Padding | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L299-L333 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_esp_info | def _read_para_esp_info(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ESP_INFO parameter.
Structure of HIP ESP_INFO parameter [RFC 7402]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved | KEYMAT Index |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| OLD SPI |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| NEW SPI |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 esp_info.type Parameter Type
1 15 esp_info.critical Critical Bit
2 16 esp_info.length Length of Contents
4 32 - Reserved
6 48 esp_info.index KEYMAT Index
8 64 esp_info.old_spi OLD SPI
12 96 esp_info.new_spi NEW SPI
"""
if clen != 12:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_resv = self._read_fileng(2)
_kind = self._read_unpack(2)
_olds = self._read_unpack(2)
_news = self._read_unpack(2)
esp_info = dict(
type=desc,
critical=cbit,
length=clen,
index=_kind,
old_spi=_olds,
new_spi=_news,
)
return esp_info | python | def _read_para_esp_info(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ESP_INFO parameter.
Structure of HIP ESP_INFO parameter [RFC 7402]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved | KEYMAT Index |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| OLD SPI |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| NEW SPI |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 esp_info.type Parameter Type
1 15 esp_info.critical Critical Bit
2 16 esp_info.length Length of Contents
4 32 - Reserved
6 48 esp_info.index KEYMAT Index
8 64 esp_info.old_spi OLD SPI
12 96 esp_info.new_spi NEW SPI
"""
if clen != 12:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_resv = self._read_fileng(2)
_kind = self._read_unpack(2)
_olds = self._read_unpack(2)
_news = self._read_unpack(2)
esp_info = dict(
type=desc,
critical=cbit,
length=clen,
index=_kind,
old_spi=_olds,
new_spi=_news,
)
return esp_info | Read HIP ESP_INFO parameter.
Structure of HIP ESP_INFO parameter [RFC 7402]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved | KEYMAT Index |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| OLD SPI |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| NEW SPI |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 esp_info.type Parameter Type
1 15 esp_info.critical Critical Bit
2 16 esp_info.length Length of Contents
4 32 - Reserved
6 48 esp_info.index KEYMAT Index
8 64 esp_info.old_spi OLD SPI
12 96 esp_info.new_spi NEW SPI | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L335-L378 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_r1_counter | def _read_para_r1_counter(self, code, cbit, clen, *, desc, length, version):
"""Read HIP R1_COUNTER parameter.
Structure of HIP R1_COUNTER parameter [RFC 5201][RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved, 4 bytes |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| R1 generation counter, 8 bytes |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 ri_counter.type Parameter Type
1 15 ri_counter.critical Critical Bit
2 16 ri_counter.length Length of Contents
4 32 - Reserved
8 64 ri_counter.count Generation of Valid Puzzles
"""
if clen != 12:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
if code == 128 and version != 1:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid parameter')
_resv = self._read_fileng(4)
_genc = self._read_unpack(8)
r1_counter = dict(
type=desc,
critical=cbit,
length=clen,
count=_genc,
)
return r1_counter | python | def _read_para_r1_counter(self, code, cbit, clen, *, desc, length, version):
"""Read HIP R1_COUNTER parameter.
Structure of HIP R1_COUNTER parameter [RFC 5201][RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved, 4 bytes |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| R1 generation counter, 8 bytes |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 ri_counter.type Parameter Type
1 15 ri_counter.critical Critical Bit
2 16 ri_counter.length Length of Contents
4 32 - Reserved
8 64 ri_counter.count Generation of Valid Puzzles
"""
if clen != 12:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
if code == 128 and version != 1:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid parameter')
_resv = self._read_fileng(4)
_genc = self._read_unpack(8)
r1_counter = dict(
type=desc,
critical=cbit,
length=clen,
count=_genc,
)
return r1_counter | Read HIP R1_COUNTER parameter.
Structure of HIP R1_COUNTER parameter [RFC 5201][RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved, 4 bytes |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| R1 generation counter, 8 bytes |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 ri_counter.type Parameter Type
1 15 ri_counter.critical Critical Bit
2 16 ri_counter.length Length of Contents
4 32 - Reserved
8 64 ri_counter.count Generation of Valid Puzzles | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L380-L418 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_locator_set | def _read_para_locator_set(self, code, cbit, clen, *, desc, length, version):
"""Read HIP LOCATOR_SET parameter.
Structure of HIP LOCATOR_SET parameter [RFC 8046]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Traffic Type | Locator Type | Locator Length | Reserved |P|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Locator Lifetime |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Locator |
| |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
. .
. .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Traffic Type | Locator Type | Locator Length | Reserved |P|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Locator Lifetime |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Locator |
| |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 locator_set.type Parameter Type
1 15 locator_set.critical Critical Bit
2 16 locator_set.length Length of Contents
4 32 locator.traffic Traffic Type
5 40 locator.type Locator Type
6 48 locator.length Locator Length
7 56 - Reserved
7 63 locator.preferred Preferred Locator
8 64 locator.lifetime Locator Lifetime
12 96 locator.object Locator
............
"""
def _read_locator(kind, size):
if kind == 0 and size == 16:
return ipaddress.ip_address(self._read_fileng(16))
elif kind == 1 and size == 20:
return dict(
spi=self._read_unpack(4),
ip=ipaddress.ip_address(self._read_fileng(16)),
)
else:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_size = 0 # length of read locators
_locs = list() # list of locators
while _size < clen:
_traf = self._read_unpack(1)
_loct = self._read_unpack(1)
_locl = self._read_unpack(1) * 4
_resp = self._read_binary(1)
_life = self._read_unpack(4)
_lobj = _read_locator(_loct, _locl)
_locs.append(Info(
traffic=_traf,
type=_loct,
length=_locl,
preferred=int(_resp[7], base=2),
lifetime=_life,
object=_lobj,
))
locator_set = dict(
type=desc,
critical=cbit,
length=clen,
locator=tuple(_locs),
)
return locator_set | python | def _read_para_locator_set(self, code, cbit, clen, *, desc, length, version):
"""Read HIP LOCATOR_SET parameter.
Structure of HIP LOCATOR_SET parameter [RFC 8046]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Traffic Type | Locator Type | Locator Length | Reserved |P|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Locator Lifetime |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Locator |
| |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
. .
. .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Traffic Type | Locator Type | Locator Length | Reserved |P|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Locator Lifetime |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Locator |
| |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 locator_set.type Parameter Type
1 15 locator_set.critical Critical Bit
2 16 locator_set.length Length of Contents
4 32 locator.traffic Traffic Type
5 40 locator.type Locator Type
6 48 locator.length Locator Length
7 56 - Reserved
7 63 locator.preferred Preferred Locator
8 64 locator.lifetime Locator Lifetime
12 96 locator.object Locator
............
"""
def _read_locator(kind, size):
if kind == 0 and size == 16:
return ipaddress.ip_address(self._read_fileng(16))
elif kind == 1 and size == 20:
return dict(
spi=self._read_unpack(4),
ip=ipaddress.ip_address(self._read_fileng(16)),
)
else:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_size = 0 # length of read locators
_locs = list() # list of locators
while _size < clen:
_traf = self._read_unpack(1)
_loct = self._read_unpack(1)
_locl = self._read_unpack(1) * 4
_resp = self._read_binary(1)
_life = self._read_unpack(4)
_lobj = _read_locator(_loct, _locl)
_locs.append(Info(
traffic=_traf,
type=_loct,
length=_locl,
preferred=int(_resp[7], base=2),
lifetime=_life,
object=_lobj,
))
locator_set = dict(
type=desc,
critical=cbit,
length=clen,
locator=tuple(_locs),
)
return locator_set | Read HIP LOCATOR_SET parameter.
Structure of HIP LOCATOR_SET parameter [RFC 8046]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Traffic Type | Locator Type | Locator Length | Reserved |P|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Locator Lifetime |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Locator |
| |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
. .
. .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Traffic Type | Locator Type | Locator Length | Reserved |P|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Locator Lifetime |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Locator |
| |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 locator_set.type Parameter Type
1 15 locator_set.critical Critical Bit
2 16 locator_set.length Length of Contents
4 32 locator.traffic Traffic Type
5 40 locator.type Locator Type
6 48 locator.length Locator Length
7 56 - Reserved
7 63 locator.preferred Preferred Locator
8 64 locator.lifetime Locator Lifetime
12 96 locator.object Locator
............ | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L420-L503 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_puzzle | def _read_para_puzzle(self, code, cbit, clen, *, desc, length, version):
"""Read HIP PUZZLE parameter.
Structure of HIP PUZZLE parameter [RFC 5201][RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| #K, 1 byte | Lifetime | Opaque, 2 bytes |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Random #I, RHASH_len / 8 bytes |
/ /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 puzzle.type Parameter Type
1 15 puzzle.critical Critical Bit
2 16 puzzle.length Length of Contents
4 32 puzzle.number Number of Verified Bits
5 40 puzzle.lifetime Lifetime
6 48 puzzle.opaque Opaque
8 64 puzzle.random Random Number
"""
if version == 1 and clen != 12:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_numk = self._read_unpack(1)
_time = self._read_unpack(1)
_opak = self._read_fileng(2)
_rand = self._read_unpack(clen-4)
puzzle = dict(
type=desc,
critical=cbit,
length=clen,
number=_numk,
lifetime=2 ** (_time - 32),
opaque=_opak,
random=_rand,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return puzzle | python | def _read_para_puzzle(self, code, cbit, clen, *, desc, length, version):
"""Read HIP PUZZLE parameter.
Structure of HIP PUZZLE parameter [RFC 5201][RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| #K, 1 byte | Lifetime | Opaque, 2 bytes |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Random #I, RHASH_len / 8 bytes |
/ /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 puzzle.type Parameter Type
1 15 puzzle.critical Critical Bit
2 16 puzzle.length Length of Contents
4 32 puzzle.number Number of Verified Bits
5 40 puzzle.lifetime Lifetime
6 48 puzzle.opaque Opaque
8 64 puzzle.random Random Number
"""
if version == 1 and clen != 12:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_numk = self._read_unpack(1)
_time = self._read_unpack(1)
_opak = self._read_fileng(2)
_rand = self._read_unpack(clen-4)
puzzle = dict(
type=desc,
critical=cbit,
length=clen,
number=_numk,
lifetime=2 ** (_time - 32),
opaque=_opak,
random=_rand,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return puzzle | Read HIP PUZZLE parameter.
Structure of HIP PUZZLE parameter [RFC 5201][RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| #K, 1 byte | Lifetime | Opaque, 2 bytes |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Random #I, RHASH_len / 8 bytes |
/ /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 puzzle.type Parameter Type
1 15 puzzle.critical Critical Bit
2 16 puzzle.length Length of Contents
4 32 puzzle.number Number of Verified Bits
5 40 puzzle.lifetime Lifetime
6 48 puzzle.opaque Opaque
8 64 puzzle.random Random Number | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L505-L553 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_seq | def _read_para_seq(self, code, cbit, clen, *, desc, length, version):
"""Read HIP SEQ parameter.
Structure of HIP SEQ parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Update ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 seq.type Parameter Type
1 15 seq.critical Critical Bit
2 16 seq.length Length of Contents
4 32 seq.id Update ID
"""
if clen != 4:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_upid = self._read_unpack(4)
seq = dict(
type=desc,
critical=cbit,
length=clen,
id=_upid,
)
return seq | python | def _read_para_seq(self, code, cbit, clen, *, desc, length, version):
"""Read HIP SEQ parameter.
Structure of HIP SEQ parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Update ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 seq.type Parameter Type
1 15 seq.critical Critical Bit
2 16 seq.length Length of Contents
4 32 seq.id Update ID
"""
if clen != 4:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_upid = self._read_unpack(4)
seq = dict(
type=desc,
critical=cbit,
length=clen,
id=_upid,
)
return seq | Read HIP SEQ parameter.
Structure of HIP SEQ parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Update ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 seq.type Parameter Type
1 15 seq.critical Critical Bit
2 16 seq.length Length of Contents
4 32 seq.id Update ID | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L613-L644 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_ack | def _read_para_ack(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ACK parameter.
Structure of HIP ACK parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| peer Update ID 1 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ peer Update ID n |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 ack.type Parameter Type
1 15 ack.critical Critical Bit
2 16 ack.length Length of Contents
4 32 ack.id Peer Update ID
"""
if clen % 4 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_upid = list()
for _ in range(clen // 4):
_upid.append(self._read_unpack(4))
ack = dict(
type=desc,
critical=cbit,
length=clen,
id=tuple(_upid),
)
return ack | python | def _read_para_ack(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ACK parameter.
Structure of HIP ACK parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| peer Update ID 1 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ peer Update ID n |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 ack.type Parameter Type
1 15 ack.critical Critical Bit
2 16 ack.length Length of Contents
4 32 ack.id Peer Update ID
"""
if clen % 4 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_upid = list()
for _ in range(clen // 4):
_upid.append(self._read_unpack(4))
ack = dict(
type=desc,
critical=cbit,
length=clen,
id=tuple(_upid),
)
return ack | Read HIP ACK parameter.
Structure of HIP ACK parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| peer Update ID 1 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ peer Update ID n |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 ack.type Parameter Type
1 15 ack.critical Critical Bit
2 16 ack.length Length of Contents
4 32 ack.id Peer Update ID | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L646-L681 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_dh_group_list | def _read_para_dh_group_list(self, code, cbit, clen, *, desc, length, version):
"""Read HIP DH_GROUP_LIST parameter.
Structure of HIP DH_GROUP_LIST parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| DH GROUP ID #1| DH GROUP ID #2| DH GROUP ID #3| DH GROUP ID #4|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| DH GROUP ID #n| Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 dh_group_list.type Parameter Type
1 15 dh_group_list.critical Critical Bit
2 16 dh_group_list.length Length of Contents
4 32 dh_group_list.id DH GROUP ID
"""
_dhid = list()
for _ in range(clen):
_dhid.append(_GROUP_ID.get(self._read_unpack(1), 'Unassigned'))
dh_group_list = dict(
type=desc,
critical=cbit,
length=clen,
id=tuple(_dhid),
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return dh_group_list | python | def _read_para_dh_group_list(self, code, cbit, clen, *, desc, length, version):
"""Read HIP DH_GROUP_LIST parameter.
Structure of HIP DH_GROUP_LIST parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| DH GROUP ID #1| DH GROUP ID #2| DH GROUP ID #3| DH GROUP ID #4|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| DH GROUP ID #n| Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 dh_group_list.type Parameter Type
1 15 dh_group_list.critical Critical Bit
2 16 dh_group_list.length Length of Contents
4 32 dh_group_list.id DH GROUP ID
"""
_dhid = list()
for _ in range(clen):
_dhid.append(_GROUP_ID.get(self._read_unpack(1), 'Unassigned'))
dh_group_list = dict(
type=desc,
critical=cbit,
length=clen,
id=tuple(_dhid),
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return dh_group_list | Read HIP DH_GROUP_LIST parameter.
Structure of HIP DH_GROUP_LIST parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| DH GROUP ID #1| DH GROUP ID #2| DH GROUP ID #3| DH GROUP ID #4|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| DH GROUP ID #n| Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 dh_group_list.type Parameter Type
1 15 dh_group_list.critical Critical Bit
2 16 dh_group_list.length Length of Contents
4 32 dh_group_list.id DH GROUP ID | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L683-L719 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_diffie_hellman | def _read_para_diffie_hellman(self, code, cbit, clen, *, desc, length, version):
"""Read HIP DIFFIE_HELLMAN parameter.
Structure of HIP DIFFIE_HELLMAN parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Group ID | Public Value Length | Public Value /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 diffie_hellman.type Parameter Type
1 15 diffie_hellman.critical Critical Bit
2 16 diffie_hellman.length Length of Contents
4 32 diffie_hellman.id Group ID
5 40 diffie_hellman.pub_len Public Value Length
6 48 diffie_hellman.pub_val Public Value
? ? - Padding
"""
_gpid = self._read_unpack(1)
_vlen = self._read_unpack(2)
_pval = self._read_fileng(_vlen)
diffie_hellman = dict(
type=desc,
critical=cbit,
length=clen,
id=_GROUP_ID.get(_gpid, 'Unassigned'),
pub_len=_vlen,
pub_val=_pval,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return diffie_hellman | python | def _read_para_diffie_hellman(self, code, cbit, clen, *, desc, length, version):
"""Read HIP DIFFIE_HELLMAN parameter.
Structure of HIP DIFFIE_HELLMAN parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Group ID | Public Value Length | Public Value /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 diffie_hellman.type Parameter Type
1 15 diffie_hellman.critical Critical Bit
2 16 diffie_hellman.length Length of Contents
4 32 diffie_hellman.id Group ID
5 40 diffie_hellman.pub_len Public Value Length
6 48 diffie_hellman.pub_val Public Value
? ? - Padding
"""
_gpid = self._read_unpack(1)
_vlen = self._read_unpack(2)
_pval = self._read_fileng(_vlen)
diffie_hellman = dict(
type=desc,
critical=cbit,
length=clen,
id=_GROUP_ID.get(_gpid, 'Unassigned'),
pub_len=_vlen,
pub_val=_pval,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return diffie_hellman | Read HIP DIFFIE_HELLMAN parameter.
Structure of HIP DIFFIE_HELLMAN parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Group ID | Public Value Length | Public Value /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 diffie_hellman.type Parameter Type
1 15 diffie_hellman.critical Critical Bit
2 16 diffie_hellman.length Length of Contents
4 32 diffie_hellman.id Group ID
5 40 diffie_hellman.pub_len Public Value Length
6 48 diffie_hellman.pub_val Public Value
? ? - Padding | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L721-L764 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_hip_transform | def _read_para_hip_transform(self, code, cbit, clen, *, desc, length, version):
"""Read HIP HIP_TRANSFORM parameter.
Structure of HIP HIP_TRANSFORM parameter [RFC 5201]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Suite ID #1 | Suite ID #2 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Suite ID #n | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hip_transform.type Parameter Type
1 15 hip_transform.critical Critical Bit
2 16 hip_transform.length Length of Contents
4 32 hip_transform.id Group ID
............
? ? - Padding
"""
if version != 1:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid parameter')
if clen % 2 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_stid = list()
for _ in range(clen // 2):
_stid.append(_SUITE_ID.get(self._read_unpack(2), 'Unassigned'))
hip_transform = dict(
type=desc,
critical=cbit,
length=clen,
id=_stid,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return hip_transform | python | def _read_para_hip_transform(self, code, cbit, clen, *, desc, length, version):
"""Read HIP HIP_TRANSFORM parameter.
Structure of HIP HIP_TRANSFORM parameter [RFC 5201]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Suite ID #1 | Suite ID #2 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Suite ID #n | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hip_transform.type Parameter Type
1 15 hip_transform.critical Critical Bit
2 16 hip_transform.length Length of Contents
4 32 hip_transform.id Group ID
............
? ? - Padding
"""
if version != 1:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid parameter')
if clen % 2 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_stid = list()
for _ in range(clen // 2):
_stid.append(_SUITE_ID.get(self._read_unpack(2), 'Unassigned'))
hip_transform = dict(
type=desc,
critical=cbit,
length=clen,
id=_stid,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return hip_transform | Read HIP HIP_TRANSFORM parameter.
Structure of HIP HIP_TRANSFORM parameter [RFC 5201]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Suite ID #1 | Suite ID #2 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Suite ID #n | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hip_transform.type Parameter Type
1 15 hip_transform.critical Critical Bit
2 16 hip_transform.length Length of Contents
4 32 hip_transform.id Group ID
............
? ? - Padding | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L766-L809 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_hip_cipher | def _read_para_hip_cipher(self, code, cbit, clen, *, desc, length, version):
"""Read HIP HIP_CIPHER parameter.
Structure of HIP HIP_CIPHER parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Cipher ID #1 | Cipher ID #2 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Cipher ID #n | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hip_cipher.type Parameter Type
1 15 hip_cipher.critical Critical Bit
2 16 hip_cipher.length Length of Contents
4 32 hip_cipher.id Cipher ID
............
? ? - Padding
"""
if clen % 2 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_cpid = list()
for _ in range(clen // 2):
_cpid.append(_CIPHER_ID.get(self._read_unpack(2), 'Unassigned'))
hip_cipher = dict(
type=desc,
critical=cbit,
length=clen,
id=_cpid,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return hip_cipher | python | def _read_para_hip_cipher(self, code, cbit, clen, *, desc, length, version):
"""Read HIP HIP_CIPHER parameter.
Structure of HIP HIP_CIPHER parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Cipher ID #1 | Cipher ID #2 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Cipher ID #n | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hip_cipher.type Parameter Type
1 15 hip_cipher.critical Critical Bit
2 16 hip_cipher.length Length of Contents
4 32 hip_cipher.id Cipher ID
............
? ? - Padding
"""
if clen % 2 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_cpid = list()
for _ in range(clen // 2):
_cpid.append(_CIPHER_ID.get(self._read_unpack(2), 'Unassigned'))
hip_cipher = dict(
type=desc,
critical=cbit,
length=clen,
id=_cpid,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return hip_cipher | Read HIP HIP_CIPHER parameter.
Structure of HIP HIP_CIPHER parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Cipher ID #1 | Cipher ID #2 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Cipher ID #n | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hip_cipher.type Parameter Type
1 15 hip_cipher.critical Critical Bit
2 16 hip_cipher.length Length of Contents
4 32 hip_cipher.id Cipher ID
............
? ? - Padding | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L811-L852 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_nat_traversal_mode | def _read_para_nat_traversal_mode(self, code, cbit, clen, *, desc, length, version):
"""Read HIP NAT_TRAVERSAL_MODE parameter.
Structure of HIP NAT_TRAVERSAL_MODE parameter [RFC 5770]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved | Mode ID #1 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Mode ID #2 | Mode ID #3 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Mode ID #n | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 nat_traversal_mode.type Parameter Type
1 15 nat_traversal_mode.critical Critical Bit
2 16 nat_traversal_mode.length Length of Contents
4 32 - Reserved
6 48 nat_traversal_mode.id Mode ID
............
? ? - Padding
"""
if clen % 2 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_resv = self._read_fileng(2)
_mdid = list()
for _ in range((clen - 2) // 2):
_mdid.append(_MODE_ID.get(self._read_unpack(2), 'Unassigned'))
nat_traversal_mode = dict(
type=desc,
critical=cbit,
length=clen,
id=_mdid,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return nat_traversal_mode | python | def _read_para_nat_traversal_mode(self, code, cbit, clen, *, desc, length, version):
"""Read HIP NAT_TRAVERSAL_MODE parameter.
Structure of HIP NAT_TRAVERSAL_MODE parameter [RFC 5770]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved | Mode ID #1 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Mode ID #2 | Mode ID #3 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Mode ID #n | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 nat_traversal_mode.type Parameter Type
1 15 nat_traversal_mode.critical Critical Bit
2 16 nat_traversal_mode.length Length of Contents
4 32 - Reserved
6 48 nat_traversal_mode.id Mode ID
............
? ? - Padding
"""
if clen % 2 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_resv = self._read_fileng(2)
_mdid = list()
for _ in range((clen - 2) // 2):
_mdid.append(_MODE_ID.get(self._read_unpack(2), 'Unassigned'))
nat_traversal_mode = dict(
type=desc,
critical=cbit,
length=clen,
id=_mdid,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return nat_traversal_mode | Read HIP NAT_TRAVERSAL_MODE parameter.
Structure of HIP NAT_TRAVERSAL_MODE parameter [RFC 5770]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved | Mode ID #1 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Mode ID #2 | Mode ID #3 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Mode ID #n | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 nat_traversal_mode.type Parameter Type
1 15 nat_traversal_mode.critical Critical Bit
2 16 nat_traversal_mode.length Length of Contents
4 32 - Reserved
6 48 nat_traversal_mode.id Mode ID
............
? ? - Padding | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L854-L899 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_transaction_pacing | def _read_para_transaction_pacing(self, code, cbit, clen, *, desc, length, version):
"""Read HIP TRANSACTION_PACING parameter.
Structure of HIP TRANSACTION_PACING parameter [RFC 5770]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Min Ta |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 transaction_pacing.type Parameter Type
1 15 transaction_pacing.critical Critical Bit
2 16 transaction_pacing.length Length of Contents
4 32 transaction_pacing.min_ta Min Ta
"""
if clen != 4:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_data = self._read_unpack(4)
transaction_pacing = dict(
type=desc,
critical=cbit,
length=clen,
min_ta=_data,
)
return transaction_pacing | python | def _read_para_transaction_pacing(self, code, cbit, clen, *, desc, length, version):
"""Read HIP TRANSACTION_PACING parameter.
Structure of HIP TRANSACTION_PACING parameter [RFC 5770]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Min Ta |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 transaction_pacing.type Parameter Type
1 15 transaction_pacing.critical Critical Bit
2 16 transaction_pacing.length Length of Contents
4 32 transaction_pacing.min_ta Min Ta
"""
if clen != 4:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_data = self._read_unpack(4)
transaction_pacing = dict(
type=desc,
critical=cbit,
length=clen,
min_ta=_data,
)
return transaction_pacing | Read HIP TRANSACTION_PACING parameter.
Structure of HIP TRANSACTION_PACING parameter [RFC 5770]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Min Ta |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 transaction_pacing.type Parameter Type
1 15 transaction_pacing.critical Critical Bit
2 16 transaction_pacing.length Length of Contents
4 32 transaction_pacing.min_ta Min Ta | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L901-L932 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_encrypted | def _read_para_encrypted(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ENCRYPTED parameter.
Structure of HIP ENCRYPTED parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| IV /
/ /
/ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /
/ Encrypted data /
/ /
/ +-------------------------------+
/ | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 encrypted.type Parameter Type
1 15 encrypted.critical Critical Bit
2 16 encrypted.length Length of Contents
4 32 - Reserved
8 48 encrypted.iv Initialization Vector
? ? encrypted.data Encrypted data
? ? - Padding
"""
_resv = self._read_fileng(4)
_data = self._read_fileng(clen-4)
encrypted = dict(
type=desc,
critical=cbit,
length=clen,
raw=_data,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return encrypted | python | def _read_para_encrypted(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ENCRYPTED parameter.
Structure of HIP ENCRYPTED parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| IV /
/ /
/ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /
/ Encrypted data /
/ /
/ +-------------------------------+
/ | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 encrypted.type Parameter Type
1 15 encrypted.critical Critical Bit
2 16 encrypted.length Length of Contents
4 32 - Reserved
8 48 encrypted.iv Initialization Vector
? ? encrypted.data Encrypted data
? ? - Padding
"""
_resv = self._read_fileng(4)
_data = self._read_fileng(clen-4)
encrypted = dict(
type=desc,
critical=cbit,
length=clen,
raw=_data,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return encrypted | Read HIP ENCRYPTED parameter.
Structure of HIP ENCRYPTED parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| IV /
/ /
/ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /
/ Encrypted data /
/ /
/ +-------------------------------+
/ | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 encrypted.type Parameter Type
1 15 encrypted.critical Critical Bit
2 16 encrypted.length Length of Contents
4 32 - Reserved
8 48 encrypted.iv Initialization Vector
? ? encrypted.data Encrypted data
? ? - Padding | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L934-L980 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_host_id | def _read_para_host_id(self, code, cbit, clen, *, desc, length, version):
"""Read HIP HOST_ID parameter.
Structure of HIP HOST_ID parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| HI Length |DI-Type| DI Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Algorithm | Host Identity /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | Domain Identifier /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 host_id.type Parameter Type
1 15 host_id.critical Critical Bit
2 16 host_id.length Length of Contents
4 32 host_id.id_len Host Identity Length
6 48 host_id.di_type Domain Identifier Type
6 52 host_id.di_len Domain Identifier Length
8 64 host_id.algorithm Algorithm
10 80 host_id.host_id Host Identity
? ? host_id.domain_id Domain Identifier
? ? - Padding
"""
def _read_host_identifier(length, code):
algorithm = _HI_ALGORITHM.get(code, 'Unassigned')
if algorithm == 'ECDSA':
host_id = dict(
curve=_ECDSA_CURVE.get(self._read_unpack(2)),
pubkey=self._read_fileng(length-2),
)
elif algorithm == 'ECDSA_LOW':
host_id = dict(
curve=_ECDSA_LOW_CURVE.get(self._read_unpack(2)),
pubkey=self._read_fileng(length-2),
)
else:
host_id = self._read_fileng(length)
return algorithm, host_id
def _read_domain_identifier(di_data):
di_type = _DI_TYPE.get(int(di_data[:4], base=2), 'Unassigned')
di_len = int(di_data[4:], base=2)
domain_id = self._read_fileng(di_len)
return di_type, di_len, domain_id
_hlen = self._read_unpack(2)
_didt = self._read_binary(2)
_algo = self._read_unpack(2)
_hidf = _read_host_identifier(_hlen, _algo)
_didf = _read_domain_identifier(_didt)
host_id = dict(
type=desc,
critical=cbit,
length=clen,
id_len=_hlen,
di_type=_didf[0],
di_len=_didf[1],
algorithm=_hidf[0],
host_id=_hidf[1],
domain_id=_didf[2],
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return host_id | python | def _read_para_host_id(self, code, cbit, clen, *, desc, length, version):
"""Read HIP HOST_ID parameter.
Structure of HIP HOST_ID parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| HI Length |DI-Type| DI Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Algorithm | Host Identity /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | Domain Identifier /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 host_id.type Parameter Type
1 15 host_id.critical Critical Bit
2 16 host_id.length Length of Contents
4 32 host_id.id_len Host Identity Length
6 48 host_id.di_type Domain Identifier Type
6 52 host_id.di_len Domain Identifier Length
8 64 host_id.algorithm Algorithm
10 80 host_id.host_id Host Identity
? ? host_id.domain_id Domain Identifier
? ? - Padding
"""
def _read_host_identifier(length, code):
algorithm = _HI_ALGORITHM.get(code, 'Unassigned')
if algorithm == 'ECDSA':
host_id = dict(
curve=_ECDSA_CURVE.get(self._read_unpack(2)),
pubkey=self._read_fileng(length-2),
)
elif algorithm == 'ECDSA_LOW':
host_id = dict(
curve=_ECDSA_LOW_CURVE.get(self._read_unpack(2)),
pubkey=self._read_fileng(length-2),
)
else:
host_id = self._read_fileng(length)
return algorithm, host_id
def _read_domain_identifier(di_data):
di_type = _DI_TYPE.get(int(di_data[:4], base=2), 'Unassigned')
di_len = int(di_data[4:], base=2)
domain_id = self._read_fileng(di_len)
return di_type, di_len, domain_id
_hlen = self._read_unpack(2)
_didt = self._read_binary(2)
_algo = self._read_unpack(2)
_hidf = _read_host_identifier(_hlen, _algo)
_didf = _read_domain_identifier(_didt)
host_id = dict(
type=desc,
critical=cbit,
length=clen,
id_len=_hlen,
di_type=_didf[0],
di_len=_didf[1],
algorithm=_hidf[0],
host_id=_hidf[1],
domain_id=_didf[2],
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return host_id | Read HIP HOST_ID parameter.
Structure of HIP HOST_ID parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| HI Length |DI-Type| DI Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Algorithm | Host Identity /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | Domain Identifier /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 host_id.type Parameter Type
1 15 host_id.critical Critical Bit
2 16 host_id.length Length of Contents
4 32 host_id.id_len Host Identity Length
6 48 host_id.di_type Domain Identifier Type
6 52 host_id.di_len Domain Identifier Length
8 64 host_id.algorithm Algorithm
10 80 host_id.host_id Host Identity
? ? host_id.domain_id Domain Identifier
? ? - Padding | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L982-L1058 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_hit_suite_list | def _read_para_hit_suite_list(self, code, cbit, clen, *, desc, length, version):
"""Read HIP HIT_SUITE_LIST parameter.
Structure of HIP HIT_SUITE_LIST parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ID #1 | ID #2 | ID #3 | ID #4 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ID #n | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hit_suite_list.type Parameter Type
1 15 hit_suite_list.critical Critical Bit
2 16 hit_suite_list.length Length of Contents
4 32 hit_suite_list.id HIT Suite ID
............
? ? - Padding
"""
_hsid = list()
for _ in range(clen):
_hsid.append(_HIT_SUITE_ID.get(self._read_unpack(1), 'Unassigned'))
hit_suite_list = dict(
type=desc,
critical=cbit,
length=clen,
id=tuple(_hsid),
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return hit_suite_list | python | def _read_para_hit_suite_list(self, code, cbit, clen, *, desc, length, version):
"""Read HIP HIT_SUITE_LIST parameter.
Structure of HIP HIT_SUITE_LIST parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ID #1 | ID #2 | ID #3 | ID #4 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ID #n | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hit_suite_list.type Parameter Type
1 15 hit_suite_list.critical Critical Bit
2 16 hit_suite_list.length Length of Contents
4 32 hit_suite_list.id HIT Suite ID
............
? ? - Padding
"""
_hsid = list()
for _ in range(clen):
_hsid.append(_HIT_SUITE_ID.get(self._read_unpack(1), 'Unassigned'))
hit_suite_list = dict(
type=desc,
critical=cbit,
length=clen,
id=tuple(_hsid),
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return hit_suite_list | Read HIP HIT_SUITE_LIST parameter.
Structure of HIP HIT_SUITE_LIST parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ID #1 | ID #2 | ID #3 | ID #4 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ID #n | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hit_suite_list.type Parameter Type
1 15 hit_suite_list.critical Critical Bit
2 16 hit_suite_list.length Length of Contents
4 32 hit_suite_list.id HIT Suite ID
............
? ? - Padding | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L1060-L1098 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_cert | def _read_para_cert(self, code, cbit, clen, *, desc, length, version):
"""Read HIP CERT parameter.
Structure of HIP CERT parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| CERT group | CERT count | CERT ID | CERT type |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Certificate /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | Padding (variable length) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 cert.type Parameter Type
1 15 cert.critical Critical Bit
2 16 cert.length Length of Contents
4 32 cert.group CERT Group
5 40 cert.count CERT Count
6 48 cert.id CERT ID
7 56 cert.cert_type CERT Type
8 64 cert.certificate Certificate
? ? - Padding
"""
_ctgp = self._read_unpack(1)
_ctct = self._read_unpack(1)
_ctid = self._read_unpack(1)
_cttp = self._read_unpack(1)
_ctdt = self._read_fileng(clen-4)
cert = dict(
type=desc,
critical=cbit,
length=clen,
group=_GROUP_ID.get(_ctgp, 'Unassigned'),
count=_ctct,
id=_ctid,
cert_type=_CERT_TYPE.get(_cttp, 'Unassigned'),
certificate=_ctdt,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return cert | python | def _read_para_cert(self, code, cbit, clen, *, desc, length, version):
"""Read HIP CERT parameter.
Structure of HIP CERT parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| CERT group | CERT count | CERT ID | CERT type |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Certificate /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | Padding (variable length) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 cert.type Parameter Type
1 15 cert.critical Critical Bit
2 16 cert.length Length of Contents
4 32 cert.group CERT Group
5 40 cert.count CERT Count
6 48 cert.id CERT ID
7 56 cert.cert_type CERT Type
8 64 cert.certificate Certificate
? ? - Padding
"""
_ctgp = self._read_unpack(1)
_ctct = self._read_unpack(1)
_ctid = self._read_unpack(1)
_cttp = self._read_unpack(1)
_ctdt = self._read_fileng(clen-4)
cert = dict(
type=desc,
critical=cbit,
length=clen,
group=_GROUP_ID.get(_ctgp, 'Unassigned'),
count=_ctct,
id=_ctid,
cert_type=_CERT_TYPE.get(_cttp, 'Unassigned'),
certificate=_ctdt,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return cert | Read HIP CERT parameter.
Structure of HIP CERT parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| CERT group | CERT count | CERT ID | CERT type |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Certificate /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | Padding (variable length) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 cert.type Parameter Type
1 15 cert.critical Critical Bit
2 16 cert.length Length of Contents
4 32 cert.group CERT Group
5 40 cert.count CERT Count
6 48 cert.id CERT ID
7 56 cert.cert_type CERT Type
8 64 cert.certificate Certificate
? ? - Padding | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L1100-L1149 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_notification | def _read_para_notification(self, code, cbit, clen, *, desc, length, version):
"""Read HIP NOTIFICATION parameter.
Structure of HIP NOTIFICATION parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved | Notify Message Type |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| /
/ Notification Data /
/ +---------------+
/ | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 notification.type Parameter Type
1 15 notification.critical Critical Bit
2 16 notification.length Length of Contents
4 32 - Reserved
6 48 notification.msg_type Notify Message Type
8 64 notification.data Notification Data
? ? - Padding
"""
_resv = self._read_fileng(2)
_code = self._read_unpack(2)
_data = self._read_fileng(2)
_type = _NOTIFICATION_TYPE.get(_code)
if _type is None:
if 1 <= _code <= 50:
_type = 'Unassigned (IETF Review)'
elif 51 <= _code <= 8191:
_type = 'Unassigned (Specification Required; Error Message)'
elif 8192 <= _code <= 16383:
_type = 'Unassigned (Reserved for Private Use; Error Message)'
elif 16384 <= _code <= 40959:
_type = 'Unassigned (Specification Required; Status Message)'
elif 40960 <= _code <= 65535:
_type = 'Unassigned (Reserved for Private Use; Status Message)'
else:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
notification = dict(
type=desc,
critical=cbit,
length=clen,
msg_type=_type,
data=_data,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return notification | python | def _read_para_notification(self, code, cbit, clen, *, desc, length, version):
"""Read HIP NOTIFICATION parameter.
Structure of HIP NOTIFICATION parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved | Notify Message Type |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| /
/ Notification Data /
/ +---------------+
/ | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 notification.type Parameter Type
1 15 notification.critical Critical Bit
2 16 notification.length Length of Contents
4 32 - Reserved
6 48 notification.msg_type Notify Message Type
8 64 notification.data Notification Data
? ? - Padding
"""
_resv = self._read_fileng(2)
_code = self._read_unpack(2)
_data = self._read_fileng(2)
_type = _NOTIFICATION_TYPE.get(_code)
if _type is None:
if 1 <= _code <= 50:
_type = 'Unassigned (IETF Review)'
elif 51 <= _code <= 8191:
_type = 'Unassigned (Specification Required; Error Message)'
elif 8192 <= _code <= 16383:
_type = 'Unassigned (Reserved for Private Use; Error Message)'
elif 16384 <= _code <= 40959:
_type = 'Unassigned (Specification Required; Status Message)'
elif 40960 <= _code <= 65535:
_type = 'Unassigned (Reserved for Private Use; Status Message)'
else:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
notification = dict(
type=desc,
critical=cbit,
length=clen,
msg_type=_type,
data=_data,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return notification | Read HIP NOTIFICATION parameter.
Structure of HIP NOTIFICATION parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved | Notify Message Type |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| /
/ Notification Data /
/ +---------------+
/ | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 notification.type Parameter Type
1 15 notification.critical Critical Bit
2 16 notification.length Length of Contents
4 32 - Reserved
6 48 notification.msg_type Notify Message Type
8 64 notification.data Notification Data
? ? - Padding | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L1151-L1209 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_echo_request_signed | def _read_para_echo_request_signed(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ECHO_REQUEST_SIGNED parameter.
Structure of HIP ECHO_REQUEST_SIGNED parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Opaque data (variable length) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 echo_request_signed.type Parameter Type
1 15 echo_request_signed.critical Critical Bit
2 16 echo_request_signed.length Length of Contents
4 32 echo_request_signed.data Opaque Data
"""
_data = self._read_fileng(clen)
echo_request_signed = dict(
type=desc,
critical=cbit,
length=clen,
data=_data,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return echo_request_signed | python | def _read_para_echo_request_signed(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ECHO_REQUEST_SIGNED parameter.
Structure of HIP ECHO_REQUEST_SIGNED parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Opaque data (variable length) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 echo_request_signed.type Parameter Type
1 15 echo_request_signed.critical Critical Bit
2 16 echo_request_signed.length Length of Contents
4 32 echo_request_signed.data Opaque Data
"""
_data = self._read_fileng(clen)
echo_request_signed = dict(
type=desc,
critical=cbit,
length=clen,
data=_data,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return echo_request_signed | Read HIP ECHO_REQUEST_SIGNED parameter.
Structure of HIP ECHO_REQUEST_SIGNED parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Opaque data (variable length) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 echo_request_signed.type Parameter Type
1 15 echo_request_signed.critical Critical Bit
2 16 echo_request_signed.length Length of Contents
4 32 echo_request_signed.data Opaque Data | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L1211-L1243 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_reg_failed | def _read_para_reg_failed(self, code, cbit, clen, *, desc, length, version):
"""Read HIP REG_FAILED parameter.
Structure of HIP REG_FAILED parameter [RFC 8003]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Lifetime | Reg Type #1 | Reg Type #2 | Reg Type #3 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ... | ... | Reg Type #n | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Padding +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 reg_failed.type Parameter Type
1 15 reg_failed.critical Critical Bit
2 16 reg_failed.length Length of Contents
4 32 reg_failed.lifetime Lifetime
4 32 reg_failed.lifetime.min Min Lifetime
5 40 reg_failed.lifetime.max Max Lifetime
6 48 reg_failed.reg_typetype Reg Type
...........
? ? - Padding
"""
_life = collections.namedtuple('Lifetime', ('min', 'max'))
_mint = self._read_unpack(1)
_maxt = self._read_unpack(1)
_type = list()
for _ in range(clen-2):
_code = self._read_unpack(1)
_kind = _REG_FAILURE_TYPE.get(_code)
if _kind is None:
if 0 <= _code <= 200:
_kind = 'Unassigned (IETF Review)'
elif 201 <= _code <= 255:
_kind = 'Unassigned (Reserved for Private Use)'
else:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_type.append(_kind)
reg_failed = dict(
type=desc,
critical=cbit,
length=clen,
lifetime=_life(_mint, _maxt),
reg_type=tuple(_type),
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return reg_failed | python | def _read_para_reg_failed(self, code, cbit, clen, *, desc, length, version):
"""Read HIP REG_FAILED parameter.
Structure of HIP REG_FAILED parameter [RFC 8003]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Lifetime | Reg Type #1 | Reg Type #2 | Reg Type #3 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ... | ... | Reg Type #n | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Padding +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 reg_failed.type Parameter Type
1 15 reg_failed.critical Critical Bit
2 16 reg_failed.length Length of Contents
4 32 reg_failed.lifetime Lifetime
4 32 reg_failed.lifetime.min Min Lifetime
5 40 reg_failed.lifetime.max Max Lifetime
6 48 reg_failed.reg_typetype Reg Type
...........
? ? - Padding
"""
_life = collections.namedtuple('Lifetime', ('min', 'max'))
_mint = self._read_unpack(1)
_maxt = self._read_unpack(1)
_type = list()
for _ in range(clen-2):
_code = self._read_unpack(1)
_kind = _REG_FAILURE_TYPE.get(_code)
if _kind is None:
if 0 <= _code <= 200:
_kind = 'Unassigned (IETF Review)'
elif 201 <= _code <= 255:
_kind = 'Unassigned (Reserved for Private Use)'
else:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_type.append(_kind)
reg_failed = dict(
type=desc,
critical=cbit,
length=clen,
lifetime=_life(_mint, _maxt),
reg_type=tuple(_type),
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return reg_failed | Read HIP REG_FAILED parameter.
Structure of HIP REG_FAILED parameter [RFC 8003]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Lifetime | Reg Type #1 | Reg Type #2 | Reg Type #3 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ... | ... | Reg Type #n | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Padding +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 reg_failed.type Parameter Type
1 15 reg_failed.critical Critical Bit
2 16 reg_failed.length Length of Contents
4 32 reg_failed.lifetime Lifetime
4 32 reg_failed.lifetime.min Min Lifetime
5 40 reg_failed.lifetime.max Max Lifetime
6 48 reg_failed.reg_typetype Reg Type
...........
? ? - Padding | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L1419-L1475 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_reg_from | def _read_para_reg_from(self, code, cbit, clen, *, desc, length, version):
"""Read HIP REG_FROM parameter.
Structure of HIP REG_FROM parameter [RFC 5770]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Port | Protocol | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Address |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 reg_from.type Parameter Type
1 15 reg_from.critical Critical Bit
2 16 reg_from.length Length of Contents
4 32 reg_from.port Port
6 48 reg_from.protocol Protocol
7 56 - Reserved
8 64 reg_from.ip Address (IPv6)
"""
if clen != 20:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_port = self._read_unpack(2)
_ptcl = self._read_unpack(1)
_resv = self._read_fileng(1)
_addr = self._read_fileng(16)
reg_from = dict(
type=desc,
critical=cbit,
length=clen,
port=_port,
protocol=TP_PROTO.get(_ptcl),
ip=ipaddress.ip_address(_addr),
)
return reg_from | python | def _read_para_reg_from(self, code, cbit, clen, *, desc, length, version):
"""Read HIP REG_FROM parameter.
Structure of HIP REG_FROM parameter [RFC 5770]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Port | Protocol | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Address |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 reg_from.type Parameter Type
1 15 reg_from.critical Critical Bit
2 16 reg_from.length Length of Contents
4 32 reg_from.port Port
6 48 reg_from.protocol Protocol
7 56 - Reserved
8 64 reg_from.ip Address (IPv6)
"""
if clen != 20:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_port = self._read_unpack(2)
_ptcl = self._read_unpack(1)
_resv = self._read_fileng(1)
_addr = self._read_fileng(16)
reg_from = dict(
type=desc,
critical=cbit,
length=clen,
port=_port,
protocol=TP_PROTO.get(_ptcl),
ip=ipaddress.ip_address(_addr),
)
return reg_from | Read HIP REG_FROM parameter.
Structure of HIP REG_FROM parameter [RFC 5770]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Port | Protocol | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Address |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 reg_from.type Parameter Type
1 15 reg_from.critical Critical Bit
2 16 reg_from.length Length of Contents
4 32 reg_from.port Port
6 48 reg_from.protocol Protocol
7 56 - Reserved
8 64 reg_from.ip Address (IPv6) | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L1477-L1521 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_echo_response_signed | def _read_para_echo_response_signed(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ECHO_RESPONSE_SIGNED parameter.
Structure of HIP ECHO_RESPONSE_SIGNED parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Opaque data (variable length) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 echo_response_signed.type Parameter Type
1 15 echo_response_signed.critical Critical Bit
2 16 echo_response_signed.length Length of Contents
4 32 echo_response_signed.data Opaque Data
"""
_data = self._read_fileng(clen)
echo_response_signed = dict(
type=desc,
critical=cbit,
length=clen,
data=_data,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return echo_response_signed | python | def _read_para_echo_response_signed(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ECHO_RESPONSE_SIGNED parameter.
Structure of HIP ECHO_RESPONSE_SIGNED parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Opaque data (variable length) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 echo_response_signed.type Parameter Type
1 15 echo_response_signed.critical Critical Bit
2 16 echo_response_signed.length Length of Contents
4 32 echo_response_signed.data Opaque Data
"""
_data = self._read_fileng(clen)
echo_response_signed = dict(
type=desc,
critical=cbit,
length=clen,
data=_data,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return echo_response_signed | Read HIP ECHO_RESPONSE_SIGNED parameter.
Structure of HIP ECHO_RESPONSE_SIGNED parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Opaque data (variable length) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 echo_response_signed.type Parameter Type
1 15 echo_response_signed.critical Critical Bit
2 16 echo_response_signed.length Length of Contents
4 32 echo_response_signed.data Opaque Data | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L1523-L1555 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_transport_format_list | def _read_para_transport_format_list(self, code, cbit, clen, *, desc, length, version):
"""Read HIP TRANSPORT_FORMAT_LIST parameter.
Structure of HIP TRANSPORT_FORMAT_LIST parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| TF type #1 | TF type #2 /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ TF type #n | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 transport_format_list.type Parameter Type
1 15 transport_format_list.critical Critical Bit
2 16 transport_format_list.length Length of Contents
4 32 transport_format_list.tf_type TF Type
............
? ? - Padding
"""
if clen % 2 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_tfid = list()
for _ in range(clen // 2):
_tfid.append(self._read_unpack(2))
transport_format_list = dict(
type=desc,
critical=cbit,
length=clen,
tf_type=tuple(_tfid),
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return transport_format_list | python | def _read_para_transport_format_list(self, code, cbit, clen, *, desc, length, version):
"""Read HIP TRANSPORT_FORMAT_LIST parameter.
Structure of HIP TRANSPORT_FORMAT_LIST parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| TF type #1 | TF type #2 /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ TF type #n | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 transport_format_list.type Parameter Type
1 15 transport_format_list.critical Critical Bit
2 16 transport_format_list.length Length of Contents
4 32 transport_format_list.tf_type TF Type
............
? ? - Padding
"""
if clen % 2 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_tfid = list()
for _ in range(clen // 2):
_tfid.append(self._read_unpack(2))
transport_format_list = dict(
type=desc,
critical=cbit,
length=clen,
tf_type=tuple(_tfid),
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return transport_format_list | Read HIP TRANSPORT_FORMAT_LIST parameter.
Structure of HIP TRANSPORT_FORMAT_LIST parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| TF type #1 | TF type #2 /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ TF type #n | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 transport_format_list.type Parameter Type
1 15 transport_format_list.critical Critical Bit
2 16 transport_format_list.length Length of Contents
4 32 transport_format_list.tf_type TF Type
............
? ? - Padding | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L1557-L1598 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_esp_transform | def _read_para_esp_transform(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ESP_TRANSFORM parameter.
Structure of HIP ESP_TRANSFORM parameter [RFC 7402]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved | Suite ID #1 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Suite ID #2 | Suite ID #3 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Suite ID #n | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 esp_transform.type Parameter Type
1 15 esp_transform.critical Critical Bit
2 16 esp_transform.length Length of Contents
4 32 - Reserved
6 48 esp_transform.id Suite ID
............
? ? - Padding
"""
if clen % 2 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_resv = self._read_fileng(2)
_stid = list()
for _ in range((clen - 2) // 2):
_stid.append(_ESP_SUITE_ID.get(self._read_unpack(2), 'Unassigned'))
esp_transform = dict(
type=desc,
critical=cbit,
length=clen,
id=tuple(_stid),
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return esp_transform | python | def _read_para_esp_transform(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ESP_TRANSFORM parameter.
Structure of HIP ESP_TRANSFORM parameter [RFC 7402]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved | Suite ID #1 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Suite ID #2 | Suite ID #3 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Suite ID #n | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 esp_transform.type Parameter Type
1 15 esp_transform.critical Critical Bit
2 16 esp_transform.length Length of Contents
4 32 - Reserved
6 48 esp_transform.id Suite ID
............
? ? - Padding
"""
if clen % 2 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_resv = self._read_fileng(2)
_stid = list()
for _ in range((clen - 2) // 2):
_stid.append(_ESP_SUITE_ID.get(self._read_unpack(2), 'Unassigned'))
esp_transform = dict(
type=desc,
critical=cbit,
length=clen,
id=tuple(_stid),
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return esp_transform | Read HIP ESP_TRANSFORM parameter.
Structure of HIP ESP_TRANSFORM parameter [RFC 7402]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved | Suite ID #1 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Suite ID #2 | Suite ID #3 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Suite ID #n | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 esp_transform.type Parameter Type
1 15 esp_transform.critical Critical Bit
2 16 esp_transform.length Length of Contents
4 32 - Reserved
6 48 esp_transform.id Suite ID
............
? ? - Padding | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L1600-L1645 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_seq_data | def _read_para_seq_data(self, code, cbit, clen, *, desc, length, version):
"""Read HIP SEQ_DATA parameter.
Structure of HIP SEQ_DATA parameter [RFC 6078]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Sequence number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 seq_data.type Parameter Type
1 15 seq_data.critical Critical Bit
2 16 seq_data.length Length of Contents
4 32 seq_data.seq Sequence number
"""
if clen != 4:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_seqn = self._read_unpack(4)
seq_data = dict(
type=desc,
critical=cbit,
length=clen,
seq=_seqn,
)
return seq_data | python | def _read_para_seq_data(self, code, cbit, clen, *, desc, length, version):
"""Read HIP SEQ_DATA parameter.
Structure of HIP SEQ_DATA parameter [RFC 6078]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Sequence number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 seq_data.type Parameter Type
1 15 seq_data.critical Critical Bit
2 16 seq_data.length Length of Contents
4 32 seq_data.seq Sequence number
"""
if clen != 4:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_seqn = self._read_unpack(4)
seq_data = dict(
type=desc,
critical=cbit,
length=clen,
seq=_seqn,
)
return seq_data | Read HIP SEQ_DATA parameter.
Structure of HIP SEQ_DATA parameter [RFC 6078]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Sequence number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 seq_data.type Parameter Type
1 15 seq_data.critical Critical Bit
2 16 seq_data.length Length of Contents
4 32 seq_data.seq Sequence number | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L1647-L1678 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_ack_data | def _read_para_ack_data(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ACK_DATA parameter.
Structure of HIP ACK_DATA parameter [RFC 6078]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Acked Sequence number /
/ /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 ack_data.type Parameter Type
1 15 ack_data.critical Critical Bit
2 16 ack_data.length Length of Contents
4 32 ack_data.ack Acked Sequence number
"""
if clen % 4 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_ackn = list()
for _ in range(clen // 4):
_ackn.append(self._read_unpack(4))
ack_data = dict(
type=desc,
critical=cbit,
length=clen,
ack=tuple(_ackn),
)
return ack_data | python | def _read_para_ack_data(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ACK_DATA parameter.
Structure of HIP ACK_DATA parameter [RFC 6078]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Acked Sequence number /
/ /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 ack_data.type Parameter Type
1 15 ack_data.critical Critical Bit
2 16 ack_data.length Length of Contents
4 32 ack_data.ack Acked Sequence number
"""
if clen % 4 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_ackn = list()
for _ in range(clen // 4):
_ackn.append(self._read_unpack(4))
ack_data = dict(
type=desc,
critical=cbit,
length=clen,
ack=tuple(_ackn),
)
return ack_data | Read HIP ACK_DATA parameter.
Structure of HIP ACK_DATA parameter [RFC 6078]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Acked Sequence number /
/ /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 ack_data.type Parameter Type
1 15 ack_data.critical Critical Bit
2 16 ack_data.length Length of Contents
4 32 ack_data.ack Acked Sequence number | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L1680-L1714 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_payload_mic | def _read_para_payload_mic(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ACK_DATA parameter.
Structure of HIP ACK_DATA parameter [RFC 6078]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Header | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Payload Data |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
/ MIC Value /
/ +-+-+-+-+-+-+-+-+
| | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 payload_mic.type Parameter Type
1 15 payload_mic.critical Critical Bit
2 16 payload_mic.length Length of Contents
4 32 payload_mic.next Next Header
5 40 - Reserved
8 64 payload_mic.data Payload Data
12 96 payload_mic.value MIC Value
? ? - Padding
"""
_next = self._read_unpack(1)
_resv = self._read_fileng(3)
_data = self._read_fileng(4)
_micv = self._read_fileng(clen-8)
payload_mic = dict(
type=desc,
critical=cbit,
length=clen,
next=TP_PROTO.get(_next),
data=_data,
value=_micv,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return payload_mic | python | def _read_para_payload_mic(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ACK_DATA parameter.
Structure of HIP ACK_DATA parameter [RFC 6078]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Header | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Payload Data |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
/ MIC Value /
/ +-+-+-+-+-+-+-+-+
| | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 payload_mic.type Parameter Type
1 15 payload_mic.critical Critical Bit
2 16 payload_mic.length Length of Contents
4 32 payload_mic.next Next Header
5 40 - Reserved
8 64 payload_mic.data Payload Data
12 96 payload_mic.value MIC Value
? ? - Padding
"""
_next = self._read_unpack(1)
_resv = self._read_fileng(3)
_data = self._read_fileng(4)
_micv = self._read_fileng(clen-8)
payload_mic = dict(
type=desc,
critical=cbit,
length=clen,
next=TP_PROTO.get(_next),
data=_data,
value=_micv,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return payload_mic | Read HIP ACK_DATA parameter.
Structure of HIP ACK_DATA parameter [RFC 6078]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Header | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Payload Data |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
/ MIC Value /
/ +-+-+-+-+-+-+-+-+
| | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 payload_mic.type Parameter Type
1 15 payload_mic.critical Critical Bit
2 16 payload_mic.length Length of Contents
4 32 payload_mic.next Next Header
5 40 - Reserved
8 64 payload_mic.data Payload Data
12 96 payload_mic.value MIC Value
? ? - Padding | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L1716-L1764 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_transaction_id | def _read_para_transaction_id(self, code, cbit, clen, *, desc, length, version):
"""Read HIP TRANSACTION_ID parameter.
Structure of HIP TRANSACTION_ID parameter [RFC 6078]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identifier /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 transaction_id.type Parameter Type
1 15 transaction_id.critical Critical Bit
2 16 transaction_id.length Length of Contents
4 32 transaction_id.id Identifier
"""
_tsid = self._read_unpack(clen)
transaction_id = dict(
type=desc,
critical=cbit,
length=clen,
id=_tsid,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return transaction_id | python | def _read_para_transaction_id(self, code, cbit, clen, *, desc, length, version):
"""Read HIP TRANSACTION_ID parameter.
Structure of HIP TRANSACTION_ID parameter [RFC 6078]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identifier /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 transaction_id.type Parameter Type
1 15 transaction_id.critical Critical Bit
2 16 transaction_id.length Length of Contents
4 32 transaction_id.id Identifier
"""
_tsid = self._read_unpack(clen)
transaction_id = dict(
type=desc,
critical=cbit,
length=clen,
id=_tsid,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return transaction_id | Read HIP TRANSACTION_ID parameter.
Structure of HIP TRANSACTION_ID parameter [RFC 6078]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identifier /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 transaction_id.type Parameter Type
1 15 transaction_id.critical Critical Bit
2 16 transaction_id.length Length of Contents
4 32 transaction_id.id Identifier | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L1766-L1800 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_overlay_id | def _read_para_overlay_id(self, code, cbit, clen, *, desc, length, version):
"""Read HIP TRANSACTION_ID parameter.
Structure of HIP TRANSACTION_ID parameter [RFC 6079]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identifier /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 overlay_id.type Parameter Type
1 15 overlay_id.critical Critical Bit
2 16 overlay_id.length Length of Contents
4 32 overlay_id.id Identifier
"""
_olid = self._read_unpack(clen)
overlay_id = dict(
type=desc,
critical=cbit,
length=clen,
id=_olid,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return overlay_id | python | def _read_para_overlay_id(self, code, cbit, clen, *, desc, length, version):
"""Read HIP TRANSACTION_ID parameter.
Structure of HIP TRANSACTION_ID parameter [RFC 6079]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identifier /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 overlay_id.type Parameter Type
1 15 overlay_id.critical Critical Bit
2 16 overlay_id.length Length of Contents
4 32 overlay_id.id Identifier
"""
_olid = self._read_unpack(clen)
overlay_id = dict(
type=desc,
critical=cbit,
length=clen,
id=_olid,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return overlay_id | Read HIP TRANSACTION_ID parameter.
Structure of HIP TRANSACTION_ID parameter [RFC 6079]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identifier /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 overlay_id.type Parameter Type
1 15 overlay_id.critical Critical Bit
2 16 overlay_id.length Length of Contents
4 32 overlay_id.id Identifier | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L1802-L1836 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_route_dst | def _read_para_route_dst(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ROUTE_DST parameter.
Structure of HIP ROUTE_DST parameter [RFC 6028]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Flags | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| HIT #1 |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
. . .
. . .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| HIT #n |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 route_dst.type Parameter Type
1 15 route_dst.critical Critical Bit
2 16 route_dst.length Length of Contents
4 32 route_dst.flags Flags
4 32 route_dst.flags.symmetric SYMMETRIC [RFC 6028]
4 33 route_dst.flags.must_follow MUST_FOLLOW [RFC 6028]
6 48 - Reserved
8 64 route_dst.ip HIT
............
"""
if (clen - 4) % 16 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_flag = self._read_binary(2)
_resv = self._read_fileng(2)
_addr = list()
for _ in range((clen - 4) // 16):
_addr.append(ipaddress.ip_address(self._read_fileng(16)))
route_dst = dict(
type=desc,
critical=cbit,
length=clen,
flags=dict(
symmetric=True if int(_flag[0], base=2) else False,
must_follow=True if int(_flag[1], base=2) else False,
),
ip=tuple(_addr),
)
return route_dst | python | def _read_para_route_dst(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ROUTE_DST parameter.
Structure of HIP ROUTE_DST parameter [RFC 6028]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Flags | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| HIT #1 |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
. . .
. . .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| HIT #n |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 route_dst.type Parameter Type
1 15 route_dst.critical Critical Bit
2 16 route_dst.length Length of Contents
4 32 route_dst.flags Flags
4 32 route_dst.flags.symmetric SYMMETRIC [RFC 6028]
4 33 route_dst.flags.must_follow MUST_FOLLOW [RFC 6028]
6 48 - Reserved
8 64 route_dst.ip HIT
............
"""
if (clen - 4) % 16 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_flag = self._read_binary(2)
_resv = self._read_fileng(2)
_addr = list()
for _ in range((clen - 4) // 16):
_addr.append(ipaddress.ip_address(self._read_fileng(16)))
route_dst = dict(
type=desc,
critical=cbit,
length=clen,
flags=dict(
symmetric=True if int(_flag[0], base=2) else False,
must_follow=True if int(_flag[1], base=2) else False,
),
ip=tuple(_addr),
)
return route_dst | Read HIP ROUTE_DST parameter.
Structure of HIP ROUTE_DST parameter [RFC 6028]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Flags | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| HIT #1 |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
. . .
. . .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| HIT #n |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 route_dst.type Parameter Type
1 15 route_dst.critical Critical Bit
2 16 route_dst.length Length of Contents
4 32 route_dst.flags Flags
4 32 route_dst.flags.symmetric SYMMETRIC [RFC 6028]
4 33 route_dst.flags.must_follow MUST_FOLLOW [RFC 6028]
6 48 - Reserved
8 64 route_dst.ip HIT
............ | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L1838-L1895 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_hip_transport_mode | def _read_para_hip_transport_mode(self, code, cbit, clen, *, desc, length, version):
"""Read HIP HIP_TRANSPORT_MODE parameter.
Structure of HIP HIP_TRANSPORT_MODE parameter [RFC 6261]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Port | Mode ID #1 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Mode ID #2 | Mode ID #3 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Mode ID #n | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hip_transport_mode.type Parameter Type
1 15 hip_transport_mode.critical Critical Bit
2 16 hip_transport_mode.length Length of Contents
4 32 hip_transport_mode.port Port
6 48 hip_transport_mode.id Mode ID
............
? ? - Padding
"""
if clen % 2 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_port = self._read_unpack(2)
_mdid = list()
for _ in range((clen - 2) // 2):
_mdid.append(_TP_MODE_ID.get(self._read_unpack(2), 'Unassigned'))
hip_transport_mode = dict(
type=desc,
critical=cbit,
length=clen,
port=_port,
id=tuple(_mdid),
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return hip_transport_mode | python | def _read_para_hip_transport_mode(self, code, cbit, clen, *, desc, length, version):
"""Read HIP HIP_TRANSPORT_MODE parameter.
Structure of HIP HIP_TRANSPORT_MODE parameter [RFC 6261]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Port | Mode ID #1 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Mode ID #2 | Mode ID #3 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Mode ID #n | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hip_transport_mode.type Parameter Type
1 15 hip_transport_mode.critical Critical Bit
2 16 hip_transport_mode.length Length of Contents
4 32 hip_transport_mode.port Port
6 48 hip_transport_mode.id Mode ID
............
? ? - Padding
"""
if clen % 2 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_port = self._read_unpack(2)
_mdid = list()
for _ in range((clen - 2) // 2):
_mdid.append(_TP_MODE_ID.get(self._read_unpack(2), 'Unassigned'))
hip_transport_mode = dict(
type=desc,
critical=cbit,
length=clen,
port=_port,
id=tuple(_mdid),
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return hip_transport_mode | Read HIP HIP_TRANSPORT_MODE parameter.
Structure of HIP HIP_TRANSPORT_MODE parameter [RFC 6261]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Port | Mode ID #1 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Mode ID #2 | Mode ID #3 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Mode ID #n | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hip_transport_mode.type Parameter Type
1 15 hip_transport_mode.critical Critical Bit
2 16 hip_transport_mode.length Length of Contents
4 32 hip_transport_mode.port Port
6 48 hip_transport_mode.id Mode ID
............
? ? - Padding | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L1897-L1943 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_hip_mac | def _read_para_hip_mac(self, code, cbit, clen, *, desc, length, version):
"""Read HIP HIP_MAC parameter.
Structure of HIP HIP_MAC parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| HMAC |
/ /
/ +-------------------------------+
| | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hip_mac.type Parameter Type
1 15 hip_mac.critical Critical Bit
2 16 hip_mac.length Length of Contents
4 32 hip_mac.hmac HMAC
? ? - Padding
"""
_hmac = self._read_fileng(clen)
hip_mac = dict(
type=desc,
critical=cbit,
length=clen,
hmac=_hmac,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return hip_mac | python | def _read_para_hip_mac(self, code, cbit, clen, *, desc, length, version):
"""Read HIP HIP_MAC parameter.
Structure of HIP HIP_MAC parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| HMAC |
/ /
/ +-------------------------------+
| | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hip_mac.type Parameter Type
1 15 hip_mac.critical Critical Bit
2 16 hip_mac.length Length of Contents
4 32 hip_mac.hmac HMAC
? ? - Padding
"""
_hmac = self._read_fileng(clen)
hip_mac = dict(
type=desc,
critical=cbit,
length=clen,
hmac=_hmac,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return hip_mac | Read HIP HIP_MAC parameter.
Structure of HIP HIP_MAC parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| HMAC |
/ /
/ +-------------------------------+
| | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hip_mac.type Parameter Type
1 15 hip_mac.critical Critical Bit
2 16 hip_mac.length Length of Contents
4 32 hip_mac.hmac HMAC
? ? - Padding | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L1945-L1982 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_hip_mac_2 | def _read_para_hip_mac_2(self, code, cbit, clen, *, desc, length, version):
"""Read HIP HIP_MAC_2 parameter.
Structure of HIP HIP_MAC_2 parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| HMAC |
/ /
/ +-------------------------------+
| | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hip_mac_2.type Parameter Type
1 15 hip_mac_2.critical Critical Bit
2 16 hip_mac_2.length Length of Contents
4 32 hip_mac_2.hmac HMAC
? ? - Padding
"""
_hmac = self._read_fileng(clen)
hip_mac_2 = dict(
type=desc,
critical=cbit,
length=clen,
hmac=_hmac,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return hip_mac_2 | python | def _read_para_hip_mac_2(self, code, cbit, clen, *, desc, length, version):
"""Read HIP HIP_MAC_2 parameter.
Structure of HIP HIP_MAC_2 parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| HMAC |
/ /
/ +-------------------------------+
| | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hip_mac_2.type Parameter Type
1 15 hip_mac_2.critical Critical Bit
2 16 hip_mac_2.length Length of Contents
4 32 hip_mac_2.hmac HMAC
? ? - Padding
"""
_hmac = self._read_fileng(clen)
hip_mac_2 = dict(
type=desc,
critical=cbit,
length=clen,
hmac=_hmac,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return hip_mac_2 | Read HIP HIP_MAC_2 parameter.
Structure of HIP HIP_MAC_2 parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| HMAC |
/ /
/ +-------------------------------+
| | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hip_mac_2.type Parameter Type
1 15 hip_mac_2.critical Critical Bit
2 16 hip_mac_2.length Length of Contents
4 32 hip_mac_2.hmac HMAC
? ? - Padding | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L1984-L2021 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_hip_signature_2 | def _read_para_hip_signature_2(self, code, cbit, clen, *, desc, length, version):
"""Read HIP HIP_SIGNATURE_2 parameter.
Structure of HIP HIP_SIGNATURE_2 parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| SIG alg | Signature /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hip_signature_2.type Parameter Type
1 15 hip_signature_2.critical Critical Bit
2 16 hip_signature_2.length Length of Contents
4 32 hip_signature_2.algorithm SIG Algorithm
6 48 hip_signature_2.signature Signature
? ? - Padding
"""
_algo = self._read_unpack(2)
_sign = self._read_fileng(clen-2)
hip_signature_2 = dict(
type=desc,
critical=cbit,
length=clen,
algorithm=_HI_ALGORITHM.get(_algo, 'Unassigned'),
signature=_sign,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return hip_signature_2 | python | def _read_para_hip_signature_2(self, code, cbit, clen, *, desc, length, version):
"""Read HIP HIP_SIGNATURE_2 parameter.
Structure of HIP HIP_SIGNATURE_2 parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| SIG alg | Signature /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hip_signature_2.type Parameter Type
1 15 hip_signature_2.critical Critical Bit
2 16 hip_signature_2.length Length of Contents
4 32 hip_signature_2.algorithm SIG Algorithm
6 48 hip_signature_2.signature Signature
? ? - Padding
"""
_algo = self._read_unpack(2)
_sign = self._read_fileng(clen-2)
hip_signature_2 = dict(
type=desc,
critical=cbit,
length=clen,
algorithm=_HI_ALGORITHM.get(_algo, 'Unassigned'),
signature=_sign,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return hip_signature_2 | Read HIP HIP_SIGNATURE_2 parameter.
Structure of HIP HIP_SIGNATURE_2 parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| SIG alg | Signature /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 hip_signature_2.type Parameter Type
1 15 hip_signature_2.critical Critical Bit
2 16 hip_signature_2.length Length of Contents
4 32 hip_signature_2.algorithm SIG Algorithm
6 48 hip_signature_2.signature Signature
? ? - Padding | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L2023-L2061 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_echo_request_unsigned | def _read_para_echo_request_unsigned(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ECHO_REQUEST_UNSIGNED parameter.
Structure of HIP ECHO_REQUEST_UNSIGNED parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Opaque data (variable length) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 echo_request_unsigned.type Parameter Type
1 15 echo_request_unsigned.critical Critical Bit
2 16 echo_request_unsigned.length Length of Contents
4 32 echo_request_unsigned.data Opaque Data
"""
_data = self._read_fileng(clen)
echo_request_unsigned = dict(
type=desc,
critical=cbit,
length=clen,
data=_data,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return echo_request_unsigned | python | def _read_para_echo_request_unsigned(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ECHO_REQUEST_UNSIGNED parameter.
Structure of HIP ECHO_REQUEST_UNSIGNED parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Opaque data (variable length) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 echo_request_unsigned.type Parameter Type
1 15 echo_request_unsigned.critical Critical Bit
2 16 echo_request_unsigned.length Length of Contents
4 32 echo_request_unsigned.data Opaque Data
"""
_data = self._read_fileng(clen)
echo_request_unsigned = dict(
type=desc,
critical=cbit,
length=clen,
data=_data,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return echo_request_unsigned | Read HIP ECHO_REQUEST_UNSIGNED parameter.
Structure of HIP ECHO_REQUEST_UNSIGNED parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Opaque data (variable length) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 echo_request_unsigned.type Parameter Type
1 15 echo_request_unsigned.critical Critical Bit
2 16 echo_request_unsigned.length Length of Contents
4 32 echo_request_unsigned.data Opaque Data | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L2103-L2135 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_echo_response_unsigned | def _read_para_echo_response_unsigned(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ECHO_RESPONSE_UNSIGNED parameter.
Structure of HIP ECHO_RESPONSE_UNSIGNED parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Opaque data (variable length) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 echo_response_unsigned.type Parameter Type
1 15 echo_response_unsigned.critical Critical Bit
2 16 echo_response_unsigned.length Length of Contents
4 32 echo_response_unsigned.data Opaque Data
"""
_data = self._read_fileng(clen)
echo_response_unsigned = dict(
type=desc,
critical=cbit,
length=clen,
data=_data,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return echo_response_unsigned | python | def _read_para_echo_response_unsigned(self, code, cbit, clen, *, desc, length, version):
"""Read HIP ECHO_RESPONSE_UNSIGNED parameter.
Structure of HIP ECHO_RESPONSE_UNSIGNED parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Opaque data (variable length) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 echo_response_unsigned.type Parameter Type
1 15 echo_response_unsigned.critical Critical Bit
2 16 echo_response_unsigned.length Length of Contents
4 32 echo_response_unsigned.data Opaque Data
"""
_data = self._read_fileng(clen)
echo_response_unsigned = dict(
type=desc,
critical=cbit,
length=clen,
data=_data,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return echo_response_unsigned | Read HIP ECHO_RESPONSE_UNSIGNED parameter.
Structure of HIP ECHO_RESPONSE_UNSIGNED parameter [RFC 7401]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Opaque data (variable length) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 echo_response_unsigned.type Parameter Type
1 15 echo_response_unsigned.critical Critical Bit
2 16 echo_response_unsigned.length Length of Contents
4 32 echo_response_unsigned.data Opaque Data | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L2137-L2169 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_overlay_ttl | def _read_para_overlay_ttl(self, code, cbit, clen, *, desc, length, version):
"""Read HIP OVERLAY_TTL parameter.
Structure of HIP OVERLAY_TTL parameter [RFC 6078]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| TTL | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 overlay_ttl.type Parameter Type
1 15 overlay_ttl.critical Critical Bit
2 16 overlay_ttl.length Length of Contents
4 32 overlay_ttl.ttl TTL
6 48 - Reserved
"""
if clen != 4:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_ttln = self._read_unpack(2)
overlay_ttl = dict(
type=desc,
critical=cbit,
length=clen,
ttl=_ttln,
)
return overlay_ttl | python | def _read_para_overlay_ttl(self, code, cbit, clen, *, desc, length, version):
"""Read HIP OVERLAY_TTL parameter.
Structure of HIP OVERLAY_TTL parameter [RFC 6078]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| TTL | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 overlay_ttl.type Parameter Type
1 15 overlay_ttl.critical Critical Bit
2 16 overlay_ttl.length Length of Contents
4 32 overlay_ttl.ttl TTL
6 48 - Reserved
"""
if clen != 4:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_ttln = self._read_unpack(2)
overlay_ttl = dict(
type=desc,
critical=cbit,
length=clen,
ttl=_ttln,
)
return overlay_ttl | Read HIP OVERLAY_TTL parameter.
Structure of HIP OVERLAY_TTL parameter [RFC 6078]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| TTL | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 overlay_ttl.type Parameter Type
1 15 overlay_ttl.critical Critical Bit
2 16 overlay_ttl.length Length of Contents
4 32 overlay_ttl.ttl TTL
6 48 - Reserved | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L2263-L2295 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_from | def _read_para_from(self, code, cbit, clen, *, desc, length, version):
"""Read HIP FROM parameter.
Structure of HIP FROM parameter [RFC 8004]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Address |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 from.type Parameter Type
1 15 from.critical Critical Bit
2 16 from.length Length of Contents
4 32 from.ip Address
"""
if clen != 16:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_addr = self._read_fileng(16)
from_ = dict(
type=desc,
critical=cbit,
length=clen,
ip=ipaddress.ip_address(_addr),
)
return from_ | python | def _read_para_from(self, code, cbit, clen, *, desc, length, version):
"""Read HIP FROM parameter.
Structure of HIP FROM parameter [RFC 8004]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Address |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 from.type Parameter Type
1 15 from.critical Critical Bit
2 16 from.length Length of Contents
4 32 from.ip Address
"""
if clen != 16:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_addr = self._read_fileng(16)
from_ = dict(
type=desc,
critical=cbit,
length=clen,
ip=ipaddress.ip_address(_addr),
)
return from_ | Read HIP FROM parameter.
Structure of HIP FROM parameter [RFC 8004]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Address |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 from.type Parameter Type
1 15 from.critical Critical Bit
2 16 from.length Length of Contents
4 32 from.ip Address | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L2356-L2390 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_rvs_hmac | def _read_para_rvs_hmac(self, code, cbit, clen, *, desc, length, version):
"""Read HIP RVS_HMAC parameter.
Structure of HIP RVS_HMAC parameter [RFC 8004]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| HMAC |
/ /
/ +-------------------------------+
| | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 rvs_hmac.type Parameter Type
1 15 rvs_hmac.critical Critical Bit
2 16 rvs_hmac.length Length of Contents
4 32 rvs_hmac.hmac HMAC
? ? - Padding
"""
_hmac = self._read_fileng(clen)
rvs_hmac = dict(
type=desc,
critical=cbit,
length=clen,
hmac=_hmac,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return rvs_hmac | python | def _read_para_rvs_hmac(self, code, cbit, clen, *, desc, length, version):
"""Read HIP RVS_HMAC parameter.
Structure of HIP RVS_HMAC parameter [RFC 8004]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| HMAC |
/ /
/ +-------------------------------+
| | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 rvs_hmac.type Parameter Type
1 15 rvs_hmac.critical Critical Bit
2 16 rvs_hmac.length Length of Contents
4 32 rvs_hmac.hmac HMAC
? ? - Padding
"""
_hmac = self._read_fileng(clen)
rvs_hmac = dict(
type=desc,
critical=cbit,
length=clen,
hmac=_hmac,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return rvs_hmac | Read HIP RVS_HMAC parameter.
Structure of HIP RVS_HMAC parameter [RFC 8004]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| HMAC |
/ /
/ +-------------------------------+
| | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 rvs_hmac.type Parameter Type
1 15 rvs_hmac.critical Critical Bit
2 16 rvs_hmac.length Length of Contents
4 32 rvs_hmac.hmac HMAC
? ? - Padding | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L2392-L2427 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_via_rvs | def _read_para_via_rvs(self, code, cbit, clen, *, desc, length, version):
"""Read HIP VIA_RVS parameter.
Structure of HIP VIA_RVS parameter [RFC 6028]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Address |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
. . .
. . .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Address |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 via_rvs.type Parameter Type
1 15 via_rvs.critical Critical Bit
2 16 via_rvs.length Length of Contents
4 32 via_rvs.ip Address
............
"""
if clen % 16 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_addr = list()
for _ in range(clen // 16):
_addr.append(ipaddress.ip_address(self._read_fileng(16)))
via_rvs = dict(
type=desc,
critical=cbit,
length=clen,
ip=tuple(_addr),
)
return via_rvs | python | def _read_para_via_rvs(self, code, cbit, clen, *, desc, length, version):
"""Read HIP VIA_RVS parameter.
Structure of HIP VIA_RVS parameter [RFC 6028]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Address |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
. . .
. . .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Address |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 via_rvs.type Parameter Type
1 15 via_rvs.critical Critical Bit
2 16 via_rvs.length Length of Contents
4 32 via_rvs.ip Address
............
"""
if clen % 16 != 0:
raise ProtocolError(f'HIPv{version}: [Parano {code}] invalid format')
_addr = list()
for _ in range(clen // 16):
_addr.append(ipaddress.ip_address(self._read_fileng(16)))
via_rvs = dict(
type=desc,
critical=cbit,
length=clen,
ip=tuple(_addr),
)
return via_rvs | Read HIP VIA_RVS parameter.
Structure of HIP VIA_RVS parameter [RFC 6028]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Address |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
. . .
. . .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Address |
| |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 via_rvs.type Parameter Type
1 15 via_rvs.critical Critical Bit
2 16 via_rvs.length Length of Contents
4 32 via_rvs.ip Address
............ | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L2429-L2474 |
JarryShaw/PyPCAPKit | src/protocols/internet/hip.py | HIP._read_para_relay_hmac | def _read_para_relay_hmac(self, code, cbit, clen, *, desc, length, version):
"""Read HIP RELAY_HMAC parameter.
Structure of HIP RELAY_HMAC parameter [RFC 5770]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| HMAC |
/ /
/ +-------------------------------+
| | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 relay_hmac.type Parameter Type
1 15 relay_hmac.critical Critical Bit
2 16 relay_hmac.length Length of Contents
4 32 relay_hmac.hmac HMAC
? ? - Padding
"""
_hmac = self._read_fileng(clen)
relay_hmac = dict(
type=desc,
critical=cbit,
length=clen,
hmac=_hmac,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return relay_hmac | python | def _read_para_relay_hmac(self, code, cbit, clen, *, desc, length, version):
"""Read HIP RELAY_HMAC parameter.
Structure of HIP RELAY_HMAC parameter [RFC 5770]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| HMAC |
/ /
/ +-------------------------------+
| | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 relay_hmac.type Parameter Type
1 15 relay_hmac.critical Critical Bit
2 16 relay_hmac.length Length of Contents
4 32 relay_hmac.hmac HMAC
? ? - Padding
"""
_hmac = self._read_fileng(clen)
relay_hmac = dict(
type=desc,
critical=cbit,
length=clen,
hmac=_hmac,
)
_plen = length - clen
if _plen:
self._read_fileng(_plen)
return relay_hmac | Read HIP RELAY_HMAC parameter.
Structure of HIP RELAY_HMAC parameter [RFC 5770]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| HMAC |
/ /
/ +-------------------------------+
| | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 relay_hmac.type Parameter Type
1 15 relay_hmac.critical Critical Bit
2 16 relay_hmac.length Length of Contents
4 32 relay_hmac.hmac HMAC
? ? - Padding | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/hip.py#L2476-L2511 |
JarryShaw/PyPCAPKit | src/utilities/exceptions.py | stacklevel | def stacklevel():
"""Fetch current stack level."""
pcapkit = f'{os.path.sep}pcapkit{os.path.sep}'
tb = traceback.extract_stack()
for index, tbitem in enumerate(tb):
if pcapkit in tbitem[0]:
break
else:
index = len(tb)
return (index-1) | python | def stacklevel():
"""Fetch current stack level."""
pcapkit = f'{os.path.sep}pcapkit{os.path.sep}'
tb = traceback.extract_stack()
for index, tbitem in enumerate(tb):
if pcapkit in tbitem[0]:
break
else:
index = len(tb)
return (index-1) | Fetch current stack level. | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/exceptions.py#L46-L55 |
JarryShaw/PyPCAPKit | src/const/misc/linktype.py | LinkType.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return LinkType(key)
if key not in LinkType._member_map_:
extend_enum(LinkType, key, default)
return LinkType[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return LinkType(key)
if key not in LinkType._member_map_:
extend_enum(LinkType, key, default)
return LinkType[key] | Backport support for original codes. | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/misc/linktype.py#L136-L142 |
JarryShaw/PyPCAPKit | src/utilities/decorators.py | seekset | def seekset(func):
"""[ClassMethod] Read file from start then set back to original."""
@functools.wraps(func)
def seekcur(self, *args, **kw):
seek_cur = self._file.tell()
self._file.seek(self._seekset, os.SEEK_SET)
return_ = func(self, *args, **kw)
self._file.seek(seek_cur, os.SEEK_SET)
return return_
return seekcur | python | def seekset(func):
"""[ClassMethod] Read file from start then set back to original."""
@functools.wraps(func)
def seekcur(self, *args, **kw):
seek_cur = self._file.tell()
self._file.seek(self._seekset, os.SEEK_SET)
return_ = func(self, *args, **kw)
self._file.seek(seek_cur, os.SEEK_SET)
return return_
return seekcur | [ClassMethod] Read file from start then set back to original. | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/decorators.py#L21-L30 |
JarryShaw/PyPCAPKit | src/utilities/decorators.py | seekset_ng | def seekset_ng(func):
"""Read file from start then set back to original."""
@functools.wraps(func)
def seekcur(file, *args, seekset=os.SEEK_SET, **kw):
# seek_cur = file.tell()
file.seek(seekset, os.SEEK_SET)
return_ = func(file, *args, seekset=seekset, **kw)
# file.seek(seek_cur, os.SEEK_SET)
return return_
return seekcur | python | def seekset_ng(func):
"""Read file from start then set back to original."""
@functools.wraps(func)
def seekcur(file, *args, seekset=os.SEEK_SET, **kw):
# seek_cur = file.tell()
file.seek(seekset, os.SEEK_SET)
return_ = func(file, *args, seekset=seekset, **kw)
# file.seek(seek_cur, os.SEEK_SET)
return return_
return seekcur | Read file from start then set back to original. | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/decorators.py#L33-L42 |
JarryShaw/PyPCAPKit | src/utilities/decorators.py | beholder | def beholder(func):
"""[ClassMethod] Behold extraction procedure."""
@functools.wraps(func)
def behold(self, proto, length, *args, **kwargs):
seek_cur = self._file.tell()
try:
return func(proto, length, *args, **kwargs)
except Exception:
from pcapkit.protocols.raw import Raw
error = traceback.format_exc(limit=1).strip().split(os.linesep)[-1]
# error = traceback.format_exc()
self._file.seek(seek_cur, os.SEEK_SET)
next_ = Raw(io.BytesIO(self._read_fileng(length)), length, error=error)
return next_
return behold | python | def beholder(func):
"""[ClassMethod] Behold extraction procedure."""
@functools.wraps(func)
def behold(self, proto, length, *args, **kwargs):
seek_cur = self._file.tell()
try:
return func(proto, length, *args, **kwargs)
except Exception:
from pcapkit.protocols.raw import Raw
error = traceback.format_exc(limit=1).strip().split(os.linesep)[-1]
# error = traceback.format_exc()
self._file.seek(seek_cur, os.SEEK_SET)
next_ = Raw(io.BytesIO(self._read_fileng(length)), length, error=error)
return next_
return behold | [ClassMethod] Behold extraction procedure. | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/decorators.py#L45-L60 |
JarryShaw/PyPCAPKit | src/utilities/decorators.py | beholder_ng | def beholder_ng(func):
"""Behold analysis procedure."""
@functools.wraps(func)
def behold(file, length, *args, **kwargs):
seek_cur = file.tell()
try:
return func(file, length, *args, **kwargs)
except Exception:
# from pcapkit.foundation.analysis import analyse
from pcapkit.protocols.raw import Raw
error = traceback.format_exc(limit=1).strip().split(os.linesep)[-1]
# error = traceback.format_exc()
file.seek(seek_cur, os.SEEK_SET)
# raw = Raw(file, length, error=str(error))
# return analyse(raw.info, raw.protochain, raw.alias)
next_ = Raw(file, length, error=error)
return next_
return behold | python | def beholder_ng(func):
"""Behold analysis procedure."""
@functools.wraps(func)
def behold(file, length, *args, **kwargs):
seek_cur = file.tell()
try:
return func(file, length, *args, **kwargs)
except Exception:
# from pcapkit.foundation.analysis import analyse
from pcapkit.protocols.raw import Raw
error = traceback.format_exc(limit=1).strip().split(os.linesep)[-1]
# error = traceback.format_exc()
file.seek(seek_cur, os.SEEK_SET)
# raw = Raw(file, length, error=str(error))
# return analyse(raw.info, raw.protochain, raw.alias)
next_ = Raw(file, length, error=error)
return next_
return behold | Behold analysis procedure. | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/utilities/decorators.py#L63-L82 |
JarryShaw/PyPCAPKit | src/protocols/link/l2tp.py | L2TP.read_l2tp | def read_l2tp(self, length):
"""Read Layer Two Tunnelling Protocol.
Structure of L2TP header [RFC 2661]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|T|L|x|x|S|x|O|P|x|x|x|x| Ver | Length (opt) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Tunnel ID | Session ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Ns (opt) | Nr (opt) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Offset Size (opt) | Offset pad... (opt)
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 l2tp.flags Flags and Version Info
0 0 l2tp.flags.type Type (0/1)
0 1 l2tp.flags.len Length
0 2 - Reserved (must be zero)
0 4 l2tp.flags.seq Sequence
0 5 - Reserved (must be zero)
0 6 l2tp.flags.offset Offset
0 7 l2tp.flags.prio Priority
1 8 - Reserved (must be zero)
1 12 l2tp.ver Version (2)
2 16 l2tp.length Length (optional by len)
4 32 l2tp.tunnelid Tunnel ID
6 48 l2tp.sessionid Session ID
8 64 l2tp.ns Sequence Number (optional by seq)
10 80 l2tp.nr Next Sequence Number (optional by seq)
12 96 l2tp.offset Offset Size (optional by offset)
"""
if length is None:
length = len(self)
_flag = self._read_binary(1)
_vers = self._read_fileng(1).hex()[1]
_hlen = self._read_unpack(2) if int(_flag[1]) else None
_tnnl = self._read_unpack(2)
_sssn = self._read_unpack(2)
_nseq = self._read_unpack(2) if int(_flag[4]) else None
_nrec = self._read_unpack(2) if int(_flag[4]) else None
_size = self._read_unpack(2) if int(_flag[6]) else 0
l2tp = dict(
flags=dict(
type='Control' if int(_flag[0]) else 'Data',
len=True if int(_flag[1]) else False,
seq=True if int(_flag[4]) else False,
offset=True if int(_flag[6]) else False,
prio=True if int(_flag[7]) else False,
),
ver=int(_vers, base=16),
length=_hlen,
tunnelid=_tnnl,
sessionid=_sssn,
ns=_nseq,
nr=_nrec,
offset=8*_size or None,
)
hdr_len = _hlen or (6 + 2*(int(_flag[1]) + 2*int(_flag[4]) + int(_flag[6])))
l2tp['hdr_len'] = hdr_len + _size * 8
# if _size:
# l2tp['padding'] = self._read_fileng(_size * 8)
length -= l2tp['hdr_len']
l2tp['packet'] = self._read_packet(header=l2tp['hdr_len'], payload=length)
return self._decode_next_layer(l2tp, length) | python | def read_l2tp(self, length):
"""Read Layer Two Tunnelling Protocol.
Structure of L2TP header [RFC 2661]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|T|L|x|x|S|x|O|P|x|x|x|x| Ver | Length (opt) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Tunnel ID | Session ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Ns (opt) | Nr (opt) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Offset Size (opt) | Offset pad... (opt)
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 l2tp.flags Flags and Version Info
0 0 l2tp.flags.type Type (0/1)
0 1 l2tp.flags.len Length
0 2 - Reserved (must be zero)
0 4 l2tp.flags.seq Sequence
0 5 - Reserved (must be zero)
0 6 l2tp.flags.offset Offset
0 7 l2tp.flags.prio Priority
1 8 - Reserved (must be zero)
1 12 l2tp.ver Version (2)
2 16 l2tp.length Length (optional by len)
4 32 l2tp.tunnelid Tunnel ID
6 48 l2tp.sessionid Session ID
8 64 l2tp.ns Sequence Number (optional by seq)
10 80 l2tp.nr Next Sequence Number (optional by seq)
12 96 l2tp.offset Offset Size (optional by offset)
"""
if length is None:
length = len(self)
_flag = self._read_binary(1)
_vers = self._read_fileng(1).hex()[1]
_hlen = self._read_unpack(2) if int(_flag[1]) else None
_tnnl = self._read_unpack(2)
_sssn = self._read_unpack(2)
_nseq = self._read_unpack(2) if int(_flag[4]) else None
_nrec = self._read_unpack(2) if int(_flag[4]) else None
_size = self._read_unpack(2) if int(_flag[6]) else 0
l2tp = dict(
flags=dict(
type='Control' if int(_flag[0]) else 'Data',
len=True if int(_flag[1]) else False,
seq=True if int(_flag[4]) else False,
offset=True if int(_flag[6]) else False,
prio=True if int(_flag[7]) else False,
),
ver=int(_vers, base=16),
length=_hlen,
tunnelid=_tnnl,
sessionid=_sssn,
ns=_nseq,
nr=_nrec,
offset=8*_size or None,
)
hdr_len = _hlen or (6 + 2*(int(_flag[1]) + 2*int(_flag[4]) + int(_flag[6])))
l2tp['hdr_len'] = hdr_len + _size * 8
# if _size:
# l2tp['padding'] = self._read_fileng(_size * 8)
length -= l2tp['hdr_len']
l2tp['packet'] = self._read_packet(header=l2tp['hdr_len'], payload=length)
return self._decode_next_layer(l2tp, length) | Read Layer Two Tunnelling Protocol.
Structure of L2TP header [RFC 2661]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|T|L|x|x|S|x|O|P|x|x|x|x| Ver | Length (opt) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Tunnel ID | Session ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Ns (opt) | Nr (opt) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Offset Size (opt) | Offset pad... (opt)
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 l2tp.flags Flags and Version Info
0 0 l2tp.flags.type Type (0/1)
0 1 l2tp.flags.len Length
0 2 - Reserved (must be zero)
0 4 l2tp.flags.seq Sequence
0 5 - Reserved (must be zero)
0 6 l2tp.flags.offset Offset
0 7 l2tp.flags.prio Priority
1 8 - Reserved (must be zero)
1 12 l2tp.ver Version (2)
2 16 l2tp.length Length (optional by len)
4 32 l2tp.tunnelid Tunnel ID
6 48 l2tp.sessionid Session ID
8 64 l2tp.ns Sequence Number (optional by seq)
10 80 l2tp.nr Next Sequence Number (optional by seq)
12 96 l2tp.offset Offset Size (optional by offset) | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/link/l2tp.py#L84-L156 |
JarryShaw/PyPCAPKit | src/const/hip/ecdsa_low_curve.py | ECDSA_LOW_Curve.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return ECDSA_LOW_Curve(key)
if key not in ECDSA_LOW_Curve._member_map_:
extend_enum(ECDSA_LOW_Curve, key, default)
return ECDSA_LOW_Curve[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return ECDSA_LOW_Curve(key)
if key not in ECDSA_LOW_Curve._member_map_:
extend_enum(ECDSA_LOW_Curve, key, default)
return ECDSA_LOW_Curve[key] | Backport support for original codes. | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/hip/ecdsa_low_curve.py#L16-L22 |
JarryShaw/PyPCAPKit | src/const/arp/hardware.py | Hardware.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return Hardware(key)
if key not in Hardware._member_map_:
extend_enum(Hardware, key, default)
return Hardware[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return Hardware(key)
if key not in Hardware._member_map_:
extend_enum(Hardware, key, default)
return Hardware[key] | Backport support for original codes. | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/arp/hardware.py#L55-L61 |
JarryShaw/PyPCAPKit | src/protocols/link/vlan.py | VLAN.read_vlan | def read_vlan(self, length):
"""Read 802.1Q Customer VLAN Tag Type.
Structure of 802.1Q Customer VLAN Tag Type [RFC 7042]:
Octets Bits Name Description
1 0 vlan.tci Tag Control Information
1 0 vlan.tci.pcp Priority Code Point
1 3 vlan.tci.dei Drop Eligible Indicator
1 4 vlan.tci.vid VLAN Identifier
3 24 vlan.type Protocol (Internet Layer)
"""
if length is None:
length = len(self)
_tcif = self._read_binary(2)
_type = self._read_protos(2)
vlan = dict(
tci=dict(
pcp=_PCP.get(int(_tcif[:3], base=2)),
dei=True if _tcif[3] else False,
vid=int(_tcif[4:], base=2),
),
type=_type,
)
length -= 4
vlan['packet'] = self._read_packet(header=4, payload=length)
return self._decode_next_layer(vlan, _type, length) | python | def read_vlan(self, length):
"""Read 802.1Q Customer VLAN Tag Type.
Structure of 802.1Q Customer VLAN Tag Type [RFC 7042]:
Octets Bits Name Description
1 0 vlan.tci Tag Control Information
1 0 vlan.tci.pcp Priority Code Point
1 3 vlan.tci.dei Drop Eligible Indicator
1 4 vlan.tci.vid VLAN Identifier
3 24 vlan.type Protocol (Internet Layer)
"""
if length is None:
length = len(self)
_tcif = self._read_binary(2)
_type = self._read_protos(2)
vlan = dict(
tci=dict(
pcp=_PCP.get(int(_tcif[:3], base=2)),
dei=True if _tcif[3] else False,
vid=int(_tcif[4:], base=2),
),
type=_type,
)
length -= 4
vlan['packet'] = self._read_packet(header=4, payload=length)
return self._decode_next_layer(vlan, _type, length) | Read 802.1Q Customer VLAN Tag Type.
Structure of 802.1Q Customer VLAN Tag Type [RFC 7042]:
Octets Bits Name Description
1 0 vlan.tci Tag Control Information
1 0 vlan.tci.pcp Priority Code Point
1 3 vlan.tci.dei Drop Eligible Indicator
1 4 vlan.tci.vid VLAN Identifier
3 24 vlan.type Protocol (Internet Layer) | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/link/vlan.py#L83-L113 |
JarryShaw/PyPCAPKit | src/const/ipv6/tagger_id.py | TaggerId.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return TaggerId(key)
if key not in TaggerId._member_map_:
extend_enum(TaggerId, key, default)
return TaggerId[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return TaggerId(key)
if key not in TaggerId._member_map_:
extend_enum(TaggerId, key, default)
return TaggerId[key] | Backport support for original codes. | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/ipv6/tagger_id.py#L18-L24 |
JarryShaw/PyPCAPKit | src/protocols/transport/tcp.py | TCP.read_tcp | def read_tcp(self, length):
"""Read Transmission Control Protocol (TCP).
Structure of TCP header [RFC 793]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Port | Destination Port |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Acknowledgement Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Data | |U|A|P|R|S|F| |
| Offset| Reserved |R|C|S|S|Y|I| Window |
| | |G|K|H|T|N|N| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Checksum | Urgent Pointer |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| data |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 tcp.srcport Source Port
2 16 tcp.dstport Destination Port
4 32 tcp.seq Sequence Number
8 64 tcp.ack Acknowledgement Number (if ACK set)
12 96 tcp.hdr_len Data Offset
12 100 - Reserved (must be zero)
12 103 tcp.flags.ns ECN Concealment Protection (NS)
13 104 tcp.flags.cwr Congestion Window Reduced (CWR)
13 105 tcp.flags.ece ECN-Echo (ECE)
13 106 tcp.flags.urg Urgent (URG)
13 107 tcp.flags.ack Acknowledgement (ACK)
13 108 tcp.flags.psh Push Function (PSH)
13 109 tcp.flags.rst Reset Connection (RST)
13 110 tcp.flags.syn Synchronize Sequence Numbers (SYN)
13 111 tcp.flags.fin Last Packet from Sender (FIN)
14 112 tcp.window_size Size of Receive Window
16 128 tcp.checksum Checksum
18 144 tcp.urgent_pointer Urgent Pointer (if URG set)
20 160 tcp.opt TCP Options (if data offset > 5)
"""
if length is None:
length = len(self)
_srcp = self._read_unpack(2)
_dstp = self._read_unpack(2)
_seqn = self._read_unpack(4)
_ackn = self._read_unpack(4)
_lenf = self._read_binary(1)
_flag = self._read_binary(1)
_wins = self._read_unpack(2)
_csum = self._read_fileng(2)
_urgp = self._read_unpack(2)
tcp = dict(
srcport=_srcp,
dstport=_dstp,
seq=_seqn,
ack=_ackn,
hdr_len=int(_lenf[:4], base=2) * 4,
flags=dict(
ns=True if int(_lenf[7]) else False,
cwr=True if int(_flag[0]) else False,
ece=True if int(_flag[1]) else False,
urg=True if int(_flag[2]) else False,
ack=True if int(_flag[3]) else False,
psh=True if int(_flag[4]) else False,
rst=True if int(_flag[5]) else False,
syn=True if int(_flag[6]) else False,
fin=True if int(_flag[7]) else False,
),
window_size=_wins,
checksum=_csum,
urgent_pointer=_urgp,
)
# packet type flags
self._syn = True if int(_flag[6]) else False
self._ack = True if int(_flag[3]) else False
_hlen = tcp['hdr_len']
_optl = _hlen - 20
if _optl:
options = self._read_tcp_options(_optl)
tcp['opt'] = options[0] # tuple of option acronyms
tcp.update(options[1]) # merge option info to buffer
length -= _hlen
tcp['packet'] = self._read_packet(header=_hlen, payload=length)
return self._decode_next_layer(tcp, None, length) | python | def read_tcp(self, length):
"""Read Transmission Control Protocol (TCP).
Structure of TCP header [RFC 793]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Port | Destination Port |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Acknowledgement Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Data | |U|A|P|R|S|F| |
| Offset| Reserved |R|C|S|S|Y|I| Window |
| | |G|K|H|T|N|N| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Checksum | Urgent Pointer |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| data |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 tcp.srcport Source Port
2 16 tcp.dstport Destination Port
4 32 tcp.seq Sequence Number
8 64 tcp.ack Acknowledgement Number (if ACK set)
12 96 tcp.hdr_len Data Offset
12 100 - Reserved (must be zero)
12 103 tcp.flags.ns ECN Concealment Protection (NS)
13 104 tcp.flags.cwr Congestion Window Reduced (CWR)
13 105 tcp.flags.ece ECN-Echo (ECE)
13 106 tcp.flags.urg Urgent (URG)
13 107 tcp.flags.ack Acknowledgement (ACK)
13 108 tcp.flags.psh Push Function (PSH)
13 109 tcp.flags.rst Reset Connection (RST)
13 110 tcp.flags.syn Synchronize Sequence Numbers (SYN)
13 111 tcp.flags.fin Last Packet from Sender (FIN)
14 112 tcp.window_size Size of Receive Window
16 128 tcp.checksum Checksum
18 144 tcp.urgent_pointer Urgent Pointer (if URG set)
20 160 tcp.opt TCP Options (if data offset > 5)
"""
if length is None:
length = len(self)
_srcp = self._read_unpack(2)
_dstp = self._read_unpack(2)
_seqn = self._read_unpack(4)
_ackn = self._read_unpack(4)
_lenf = self._read_binary(1)
_flag = self._read_binary(1)
_wins = self._read_unpack(2)
_csum = self._read_fileng(2)
_urgp = self._read_unpack(2)
tcp = dict(
srcport=_srcp,
dstport=_dstp,
seq=_seqn,
ack=_ackn,
hdr_len=int(_lenf[:4], base=2) * 4,
flags=dict(
ns=True if int(_lenf[7]) else False,
cwr=True if int(_flag[0]) else False,
ece=True if int(_flag[1]) else False,
urg=True if int(_flag[2]) else False,
ack=True if int(_flag[3]) else False,
psh=True if int(_flag[4]) else False,
rst=True if int(_flag[5]) else False,
syn=True if int(_flag[6]) else False,
fin=True if int(_flag[7]) else False,
),
window_size=_wins,
checksum=_csum,
urgent_pointer=_urgp,
)
# packet type flags
self._syn = True if int(_flag[6]) else False
self._ack = True if int(_flag[3]) else False
_hlen = tcp['hdr_len']
_optl = _hlen - 20
if _optl:
options = self._read_tcp_options(_optl)
tcp['opt'] = options[0] # tuple of option acronyms
tcp.update(options[1]) # merge option info to buffer
length -= _hlen
tcp['packet'] = self._read_packet(header=_hlen, payload=length)
return self._decode_next_layer(tcp, None, length) | Read Transmission Control Protocol (TCP).
Structure of TCP header [RFC 793]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Port | Destination Port |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Acknowledgement Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Data | |U|A|P|R|S|F| |
| Offset| Reserved |R|C|S|S|Y|I| Window |
| | |G|K|H|T|N|N| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Checksum | Urgent Pointer |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| data |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 tcp.srcport Source Port
2 16 tcp.dstport Destination Port
4 32 tcp.seq Sequence Number
8 64 tcp.ack Acknowledgement Number (if ACK set)
12 96 tcp.hdr_len Data Offset
12 100 - Reserved (must be zero)
12 103 tcp.flags.ns ECN Concealment Protection (NS)
13 104 tcp.flags.cwr Congestion Window Reduced (CWR)
13 105 tcp.flags.ece ECN-Echo (ECE)
13 106 tcp.flags.urg Urgent (URG)
13 107 tcp.flags.ack Acknowledgement (ACK)
13 108 tcp.flags.psh Push Function (PSH)
13 109 tcp.flags.rst Reset Connection (RST)
13 110 tcp.flags.syn Synchronize Sequence Numbers (SYN)
13 111 tcp.flags.fin Last Packet from Sender (FIN)
14 112 tcp.window_size Size of Receive Window
16 128 tcp.checksum Checksum
18 144 tcp.urgent_pointer Urgent Pointer (if URG set)
20 160 tcp.opt TCP Options (if data offset > 5) | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/transport/tcp.py#L231-L328 |
JarryShaw/PyPCAPKit | src/protocols/transport/tcp.py | TCP._read_tcp_options | def _read_tcp_options(self, size):
"""Read TCP option list.
Positional arguments:
* size -- int, length of option list
Returns:
* tuple -- TCP option list
* dict -- extracted TCP option
"""
counter = 0 # length of read option list
optkind = list() # option kind list
options = dict() # dict of option data
while counter < size:
# get option kind
kind = self._read_unpack(1)
# fetch corresponding option tuple
opts = TCP_OPT.get(kind)
enum = OPT_TYPE.get(kind)
if opts is None:
len_ = size - counter
counter = size
optkind.append(enum)
options[enum.name] = self._read_fileng(len_)
break
# extract option
dscp = opts[1]
if opts[0]:
len_ = self._read_unpack(1)
byte = opts[2](len_)
if byte: # check option process mode
data = process_opt[opts[3]](self, byte, kind)
else: # permission options (length is 2)
data = dict(
kind=kind, # option kind
length=2, # option length
flag=True, # permission flag
)
else: # 1-bytes options
len_ = 1
data = dict(
kind=kind, # option kind
length=1, # option length
)
# record option data
counter += len_
if enum in optkind:
if isinstance(options[dscp], tuple):
options[dscp] += (Info(data),)
else:
options[dscp] = (Info(options[dscp]), Info(data))
else:
optkind.append(enum)
options[dscp] = data
# break when eol triggered
if not kind:
break
# get padding
if counter < size:
len_ = size - counter
options['padding'] = self._read_fileng(len_)
return tuple(optkind), options | python | def _read_tcp_options(self, size):
"""Read TCP option list.
Positional arguments:
* size -- int, length of option list
Returns:
* tuple -- TCP option list
* dict -- extracted TCP option
"""
counter = 0 # length of read option list
optkind = list() # option kind list
options = dict() # dict of option data
while counter < size:
# get option kind
kind = self._read_unpack(1)
# fetch corresponding option tuple
opts = TCP_OPT.get(kind)
enum = OPT_TYPE.get(kind)
if opts is None:
len_ = size - counter
counter = size
optkind.append(enum)
options[enum.name] = self._read_fileng(len_)
break
# extract option
dscp = opts[1]
if opts[0]:
len_ = self._read_unpack(1)
byte = opts[2](len_)
if byte: # check option process mode
data = process_opt[opts[3]](self, byte, kind)
else: # permission options (length is 2)
data = dict(
kind=kind, # option kind
length=2, # option length
flag=True, # permission flag
)
else: # 1-bytes options
len_ = 1
data = dict(
kind=kind, # option kind
length=1, # option length
)
# record option data
counter += len_
if enum in optkind:
if isinstance(options[dscp], tuple):
options[dscp] += (Info(data),)
else:
options[dscp] = (Info(options[dscp]), Info(data))
else:
optkind.append(enum)
options[dscp] = data
# break when eol triggered
if not kind:
break
# get padding
if counter < size:
len_ = size - counter
options['padding'] = self._read_fileng(len_)
return tuple(optkind), options | Read TCP option list.
Positional arguments:
* size -- int, length of option list
Returns:
* tuple -- TCP option list
* dict -- extracted TCP option | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/transport/tcp.py#L345-L414 |
JarryShaw/PyPCAPKit | src/protocols/transport/tcp.py | TCP._read_mode_donone | def _read_mode_donone(self, size, kind):
"""Read options request no process.
Positional arguments:
* size - int, length of option
* kind - int, option kind value
Returns:
* dict -- extracted option with no operation
Structure of TCP options:
Octets Bits Name Description
0 0 tcp.opt.kind Kind
1 8 tcp.opt.length Length
2 16 tcp.opt.data Kind-specific Data
"""
data = dict(
kind=kind,
length=size,
data=self._read_fileng(size),
)
return data | python | def _read_mode_donone(self, size, kind):
"""Read options request no process.
Positional arguments:
* size - int, length of option
* kind - int, option kind value
Returns:
* dict -- extracted option with no operation
Structure of TCP options:
Octets Bits Name Description
0 0 tcp.opt.kind Kind
1 8 tcp.opt.length Length
2 16 tcp.opt.data Kind-specific Data
"""
data = dict(
kind=kind,
length=size,
data=self._read_fileng(size),
)
return data | Read options request no process.
Positional arguments:
* size - int, length of option
* kind - int, option kind value
Returns:
* dict -- extracted option with no operation
Structure of TCP options:
Octets Bits Name Description
0 0 tcp.opt.kind Kind
1 8 tcp.opt.length Length
2 16 tcp.opt.data Kind-specific Data | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/transport/tcp.py#L416-L438 |
JarryShaw/PyPCAPKit | src/protocols/transport/tcp.py | TCP._read_mode_unpack | def _read_mode_unpack(self, size, kind):
"""Read options request unpack process.
Keyword arguments:
size - int, length of option
kind - int, option kind value
Returns:
* dict -- extracted option which unpacked
Structure of TCP options:
Octets Bits Name Description
0 0 tcp.opt.kind Kind
1 8 tcp.opt.length Length
2 16 tcp.opt.data Kind-specific Data
"""
data = dict(
kind=kind,
length=size,
data=self._read_unpack(size),
)
return data | python | def _read_mode_unpack(self, size, kind):
"""Read options request unpack process.
Keyword arguments:
size - int, length of option
kind - int, option kind value
Returns:
* dict -- extracted option which unpacked
Structure of TCP options:
Octets Bits Name Description
0 0 tcp.opt.kind Kind
1 8 tcp.opt.length Length
2 16 tcp.opt.data Kind-specific Data
"""
data = dict(
kind=kind,
length=size,
data=self._read_unpack(size),
)
return data | Read options request unpack process.
Keyword arguments:
size - int, length of option
kind - int, option kind value
Returns:
* dict -- extracted option which unpacked
Structure of TCP options:
Octets Bits Name Description
0 0 tcp.opt.kind Kind
1 8 tcp.opt.length Length
2 16 tcp.opt.data Kind-specific Data | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/transport/tcp.py#L440-L462 |
JarryShaw/PyPCAPKit | src/protocols/transport/tcp.py | TCP._read_mode_tsopt | def _read_mode_tsopt(self, size, kind):
"""Read Timestamps option.
Positional arguments:
* size - int, length of option
* kind - int, 8 (Timestamps)
Returns:
* dict -- extracted Timestamps (TS) option
Structure of TCP TSopt [RFC 7323]:
+-------+-------+---------------------+---------------------+
|Kind=8 | 10 | TS Value (TSval) |TS Echo Reply (TSecr)|
+-------+-------+---------------------+---------------------+
1 1 4 4
Octets Bits Name Description
0 0 tcp.ts.kind Kind (8)
1 8 tcp.ts.length Length (10)
2 16 tcp.ts.val Timestamp Value
6 48 tcp.ts.ecr Timestamps Echo Reply
"""
temp = struct.unpack('>II', self._read_fileng(size))
data = dict(
kind=kind,
length=size,
val=temp[0],
ecr=temp[1],
)
return data | python | def _read_mode_tsopt(self, size, kind):
"""Read Timestamps option.
Positional arguments:
* size - int, length of option
* kind - int, 8 (Timestamps)
Returns:
* dict -- extracted Timestamps (TS) option
Structure of TCP TSopt [RFC 7323]:
+-------+-------+---------------------+---------------------+
|Kind=8 | 10 | TS Value (TSval) |TS Echo Reply (TSecr)|
+-------+-------+---------------------+---------------------+
1 1 4 4
Octets Bits Name Description
0 0 tcp.ts.kind Kind (8)
1 8 tcp.ts.length Length (10)
2 16 tcp.ts.val Timestamp Value
6 48 tcp.ts.ecr Timestamps Echo Reply
"""
temp = struct.unpack('>II', self._read_fileng(size))
data = dict(
kind=kind,
length=size,
val=temp[0],
ecr=temp[1],
)
return data | Read Timestamps option.
Positional arguments:
* size - int, length of option
* kind - int, 8 (Timestamps)
Returns:
* dict -- extracted Timestamps (TS) option
Structure of TCP TSopt [RFC 7323]:
+-------+-------+---------------------+---------------------+
|Kind=8 | 10 | TS Value (TSval) |TS Echo Reply (TSecr)|
+-------+-------+---------------------+---------------------+
1 1 4 4
Octets Bits Name Description
0 0 tcp.ts.kind Kind (8)
1 8 tcp.ts.length Length (10)
2 16 tcp.ts.val Timestamp Value
6 48 tcp.ts.ecr Timestamps Echo Reply | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/transport/tcp.py#L464-L494 |
JarryShaw/PyPCAPKit | src/protocols/transport/tcp.py | TCP._read_mode_pocsp | def _read_mode_pocsp(self, size, kind):
"""Read Partial Order Connection Service Profile option.
Positional arguments:
* size - int, length of option
* kind - int, 10 (POC-Serv Profile)
Returns:
* dict -- extracted Partial Order Connection Service Profile (POC-SP) option
Structure of TCP POC-SP Option [RFC 1693][RFC 6247]:
1 bit 1 bit 6 bits
+----------+----------+------------+----------+--------+
| Kind=10 | Length=3 | Start_flag | End_flag | Filler |
+----------+----------+------------+----------+--------+
Octets Bits Name Description
0 0 tcp.pocsp.kind Kind (10)
1 8 tcp.pocsp.length Length (3)
2 16 tcp.pocsp.start Start Flag
2 17 tcp.pocsp.end End Flag
2 18 tcp.pocsp.filler Filler
"""
temp = self._read_binary(size)
data = dict(
kind=kind,
length=size,
start=True if int(temp[0]) else False,
end=True if int(temp[1]) else False,
filler=bytes(chr(int(temp[2:], base=2)), encoding='utf-8'),
)
return data | python | def _read_mode_pocsp(self, size, kind):
"""Read Partial Order Connection Service Profile option.
Positional arguments:
* size - int, length of option
* kind - int, 10 (POC-Serv Profile)
Returns:
* dict -- extracted Partial Order Connection Service Profile (POC-SP) option
Structure of TCP POC-SP Option [RFC 1693][RFC 6247]:
1 bit 1 bit 6 bits
+----------+----------+------------+----------+--------+
| Kind=10 | Length=3 | Start_flag | End_flag | Filler |
+----------+----------+------------+----------+--------+
Octets Bits Name Description
0 0 tcp.pocsp.kind Kind (10)
1 8 tcp.pocsp.length Length (3)
2 16 tcp.pocsp.start Start Flag
2 17 tcp.pocsp.end End Flag
2 18 tcp.pocsp.filler Filler
"""
temp = self._read_binary(size)
data = dict(
kind=kind,
length=size,
start=True if int(temp[0]) else False,
end=True if int(temp[1]) else False,
filler=bytes(chr(int(temp[2:], base=2)), encoding='utf-8'),
)
return data | Read Partial Order Connection Service Profile option.
Positional arguments:
* size - int, length of option
* kind - int, 10 (POC-Serv Profile)
Returns:
* dict -- extracted Partial Order Connection Service Profile (POC-SP) option
Structure of TCP POC-SP Option [RFC 1693][RFC 6247]:
1 bit 1 bit 6 bits
+----------+----------+------------+----------+--------+
| Kind=10 | Length=3 | Start_flag | End_flag | Filler |
+----------+----------+------------+----------+--------+
Octets Bits Name Description
0 0 tcp.pocsp.kind Kind (10)
1 8 tcp.pocsp.length Length (3)
2 16 tcp.pocsp.start Start Flag
2 17 tcp.pocsp.end End Flag
2 18 tcp.pocsp.filler Filler | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/transport/tcp.py#L496-L530 |
JarryShaw/PyPCAPKit | src/protocols/transport/tcp.py | TCP._read_mode_acopt | def _read_mode_acopt(self, size, kind):
"""Read Alternate Checksum Request option.
Positional arguments:
size - int, length of option
kind - int, 14 (Alt-Chksum Request)
Returns:
* dict -- extracted Alternate Checksum Request (CHKSUM-REQ) option
Structure of TCP CHKSUM-REQ [RFC 1146][RFC 6247]:
+----------+----------+----------+
| Kind=14 | Length=3 | chksum |
+----------+----------+----------+
Octets Bits Name Description
0 0 tcp.chksumreq.kind Kind (14)
1 8 tcp.chksumreq.length Length (3)
2 16 tcp.chksumreq.ac Checksum Algorithm
"""
temp = self._read_unpack(size)
algo = chksum_opt.get(temp)
data = dict(
kind=kind,
length=size,
ac=algo,
)
return data | python | def _read_mode_acopt(self, size, kind):
"""Read Alternate Checksum Request option.
Positional arguments:
size - int, length of option
kind - int, 14 (Alt-Chksum Request)
Returns:
* dict -- extracted Alternate Checksum Request (CHKSUM-REQ) option
Structure of TCP CHKSUM-REQ [RFC 1146][RFC 6247]:
+----------+----------+----------+
| Kind=14 | Length=3 | chksum |
+----------+----------+----------+
Octets Bits Name Description
0 0 tcp.chksumreq.kind Kind (14)
1 8 tcp.chksumreq.length Length (3)
2 16 tcp.chksumreq.ac Checksum Algorithm
"""
temp = self._read_unpack(size)
algo = chksum_opt.get(temp)
data = dict(
kind=kind,
length=size,
ac=algo,
)
return data | Read Alternate Checksum Request option.
Positional arguments:
size - int, length of option
kind - int, 14 (Alt-Chksum Request)
Returns:
* dict -- extracted Alternate Checksum Request (CHKSUM-REQ) option
Structure of TCP CHKSUM-REQ [RFC 1146][RFC 6247]:
+----------+----------+----------+
| Kind=14 | Length=3 | chksum |
+----------+----------+----------+
Octets Bits Name Description
0 0 tcp.chksumreq.kind Kind (14)
1 8 tcp.chksumreq.length Length (3)
2 16 tcp.chksumreq.ac Checksum Algorithm | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/transport/tcp.py#L532-L562 |
JarryShaw/PyPCAPKit | src/protocols/transport/tcp.py | TCP._read_mode_qsopt | def _read_mode_qsopt(self, size, kind):
"""Read Quick-Start Response option.
Positional arguments:
* size - int, length of option
* kind - int, 27 (Quick-Start Response)
Returns:
* dict -- extracted Quick-Start Response (QS) option
Structure of TCP QSopt [RFC 4782]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Kind | Length=8 | Resv. | Rate | TTL Diff |
| | | |Request| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| QS Nonce | R |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 tcp.qs.kind Kind (27)
1 8 tcp.qs.length Length (8)
2 16 - Reserved (must be zero)
2 20 tcp.qs.req_rate Request Rate
3 24 tcp.qs.ttl_diff TTL Difference
4 32 tcp.qs.nounce QS Nounce
7 62 - Reserved (must be zero)
"""
rvrr = self._read_binary(1)
ttld = self._read_unpack(1)
noun = self._read_fileng(4)
data = dict(
kind=kind,
length=size,
req_rate=int(rvrr[4:], base=2),
ttl_diff=ttld,
nounce=noun[:-2],
)
return data | python | def _read_mode_qsopt(self, size, kind):
"""Read Quick-Start Response option.
Positional arguments:
* size - int, length of option
* kind - int, 27 (Quick-Start Response)
Returns:
* dict -- extracted Quick-Start Response (QS) option
Structure of TCP QSopt [RFC 4782]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Kind | Length=8 | Resv. | Rate | TTL Diff |
| | | |Request| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| QS Nonce | R |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 tcp.qs.kind Kind (27)
1 8 tcp.qs.length Length (8)
2 16 - Reserved (must be zero)
2 20 tcp.qs.req_rate Request Rate
3 24 tcp.qs.ttl_diff TTL Difference
4 32 tcp.qs.nounce QS Nounce
7 62 - Reserved (must be zero)
"""
rvrr = self._read_binary(1)
ttld = self._read_unpack(1)
noun = self._read_fileng(4)
data = dict(
kind=kind,
length=size,
req_rate=int(rvrr[4:], base=2),
ttl_diff=ttld,
nounce=noun[:-2],
)
return data | Read Quick-Start Response option.
Positional arguments:
* size - int, length of option
* kind - int, 27 (Quick-Start Response)
Returns:
* dict -- extracted Quick-Start Response (QS) option
Structure of TCP QSopt [RFC 4782]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Kind | Length=8 | Resv. | Rate | TTL Diff |
| | | |Request| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| QS Nonce | R |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 tcp.qs.kind Kind (27)
1 8 tcp.qs.length Length (8)
2 16 - Reserved (must be zero)
2 20 tcp.qs.req_rate Request Rate
3 24 tcp.qs.ttl_diff TTL Difference
4 32 tcp.qs.nounce QS Nounce
7 62 - Reserved (must be zero) | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/transport/tcp.py#L564-L606 |
JarryShaw/PyPCAPKit | src/protocols/transport/tcp.py | TCP._read_mode_utopt | def _read_mode_utopt(self, size, kind):
"""Read User Timeout option.
Positional arguments:
* size - int, length of option
* kind - int, 28 (User Timeout Option)
Returns:
* dict -- extracted User Timeout (TIMEOUT) option
Structure of TCP TIMEOUT [RFC 5482]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Kind = 28 | Length = 4 |G| User Timeout |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 tcp.timeout.kind Kind (28)
1 8 tcp.timeout.length Length (4)
2 16 tcp.timeout.granularity Granularity
2 17 tcp.timeout.timeout User Timeout
"""
temp = self._read_fileng(size)
data = dict(
kind=kind,
length=size,
granularity='minutes' if int(temp[0]) else 'seconds',
timeout=bytes(chr(int(temp[0:], base=2)), encoding='utf-8'),
)
return data | python | def _read_mode_utopt(self, size, kind):
"""Read User Timeout option.
Positional arguments:
* size - int, length of option
* kind - int, 28 (User Timeout Option)
Returns:
* dict -- extracted User Timeout (TIMEOUT) option
Structure of TCP TIMEOUT [RFC 5482]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Kind = 28 | Length = 4 |G| User Timeout |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 tcp.timeout.kind Kind (28)
1 8 tcp.timeout.length Length (4)
2 16 tcp.timeout.granularity Granularity
2 17 tcp.timeout.timeout User Timeout
"""
temp = self._read_fileng(size)
data = dict(
kind=kind,
length=size,
granularity='minutes' if int(temp[0]) else 'seconds',
timeout=bytes(chr(int(temp[0:], base=2)), encoding='utf-8'),
)
return data | Read User Timeout option.
Positional arguments:
* size - int, length of option
* kind - int, 28 (User Timeout Option)
Returns:
* dict -- extracted User Timeout (TIMEOUT) option
Structure of TCP TIMEOUT [RFC 5482]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Kind = 28 | Length = 4 |G| User Timeout |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 tcp.timeout.kind Kind (28)
1 8 tcp.timeout.length Length (4)
2 16 tcp.timeout.granularity Granularity
2 17 tcp.timeout.timeout User Timeout | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/transport/tcp.py#L608-L641 |
JarryShaw/PyPCAPKit | src/protocols/transport/tcp.py | TCP._read_mode_tcpao | def _read_mode_tcpao(self, size, kind):
"""Read Authentication option.
Positional arguments:
* size - int, length of option
* kind - int, 29 (TCP Authentication Option)
Returns:
* dict -- extracted Authentication (AO) option
Structure of TCP AOopt [RFC 5925]:
+------------+------------+------------+------------+
| Kind=29 | Length | KeyID | RNextKeyID |
+------------+------------+------------+------------+
| MAC ...
+-----------------------------------...
...-----------------+
... MAC (con't) |
...-----------------+
Octets Bits Name Description
0 0 tcp.ao.kind Kind (29)
1 8 tcp.ao.length Length
2 16 tcp.ao.keyid KeyID
3 24 tcp.ao.rnextkeyid RNextKeyID
4 32 tcp.ao.mac Message Authentication Code
"""
key_ = self._read_unpack(1)
rkey = self._read_unpack(1)
mac_ = self._read_fileng(size - 2)
data = dict(
kind=kind,
length=size,
keyid=key_,
rnextkeyid=rkey,
mac=mac_,
)
return data | python | def _read_mode_tcpao(self, size, kind):
"""Read Authentication option.
Positional arguments:
* size - int, length of option
* kind - int, 29 (TCP Authentication Option)
Returns:
* dict -- extracted Authentication (AO) option
Structure of TCP AOopt [RFC 5925]:
+------------+------------+------------+------------+
| Kind=29 | Length | KeyID | RNextKeyID |
+------------+------------+------------+------------+
| MAC ...
+-----------------------------------...
...-----------------+
... MAC (con't) |
...-----------------+
Octets Bits Name Description
0 0 tcp.ao.kind Kind (29)
1 8 tcp.ao.length Length
2 16 tcp.ao.keyid KeyID
3 24 tcp.ao.rnextkeyid RNextKeyID
4 32 tcp.ao.mac Message Authentication Code
"""
key_ = self._read_unpack(1)
rkey = self._read_unpack(1)
mac_ = self._read_fileng(size - 2)
data = dict(
kind=kind,
length=size,
keyid=key_,
rnextkeyid=rkey,
mac=mac_,
)
return data | Read Authentication option.
Positional arguments:
* size - int, length of option
* kind - int, 29 (TCP Authentication Option)
Returns:
* dict -- extracted Authentication (AO) option
Structure of TCP AOopt [RFC 5925]:
+------------+------------+------------+------------+
| Kind=29 | Length | KeyID | RNextKeyID |
+------------+------------+------------+------------+
| MAC ...
+-----------------------------------...
...-----------------+
... MAC (con't) |
...-----------------+
Octets Bits Name Description
0 0 tcp.ao.kind Kind (29)
1 8 tcp.ao.length Length
2 16 tcp.ao.keyid KeyID
3 24 tcp.ao.rnextkeyid RNextKeyID
4 32 tcp.ao.mac Message Authentication Code | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/transport/tcp.py#L643-L684 |
JarryShaw/PyPCAPKit | src/protocols/transport/tcp.py | TCP._read_mode_mptcp | def _read_mode_mptcp(self, size, kind):
"""Read Multipath TCP option.
Positional arguments:
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Multipath TCP (MP-TCP) option
Structure of MP-TCP [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-----------------------+
| Kind | Length |Subtype| |
+---------------+---------------+-------+ |
| Subtype-specific data |
| (variable length) |
+---------------------------------------------------------------+
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length
2 16 tcp.mp.subtype Subtype
2 20 tcp.mp.data Subtype-specific Data
"""
bins = self._read_binary(1)
subt = int(bins[:4], base=2) # subtype number
bits = bins[4:] # 4-bit data
dlen = size - 1 # length of remaining data
# fetch subtype-specific data
func = mptcp_opt.get(subt)
if func is None: # if subtype not exist, directly read all data
temp = self._read_fileng(dlen)
data = dict(
kind=kind,
length=size,
subtype='Unknown',
data=bytes(chr(int(bits[:4], base=2)), encoding='utf-8') + temp,
)
else: # fetch corresponding subtype data dict
data = func(self, bits, dlen, kind)
return data | python | def _read_mode_mptcp(self, size, kind):
"""Read Multipath TCP option.
Positional arguments:
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Multipath TCP (MP-TCP) option
Structure of MP-TCP [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-----------------------+
| Kind | Length |Subtype| |
+---------------+---------------+-------+ |
| Subtype-specific data |
| (variable length) |
+---------------------------------------------------------------+
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length
2 16 tcp.mp.subtype Subtype
2 20 tcp.mp.data Subtype-specific Data
"""
bins = self._read_binary(1)
subt = int(bins[:4], base=2) # subtype number
bits = bins[4:] # 4-bit data
dlen = size - 1 # length of remaining data
# fetch subtype-specific data
func = mptcp_opt.get(subt)
if func is None: # if subtype not exist, directly read all data
temp = self._read_fileng(dlen)
data = dict(
kind=kind,
length=size,
subtype='Unknown',
data=bytes(chr(int(bits[:4], base=2)), encoding='utf-8') + temp,
)
else: # fetch corresponding subtype data dict
data = func(self, bits, dlen, kind)
return data | Read Multipath TCP option.
Positional arguments:
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Multipath TCP (MP-TCP) option
Structure of MP-TCP [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-----------------------+
| Kind | Length |Subtype| |
+---------------+---------------+-------+ |
| Subtype-specific data |
| (variable length) |
+---------------------------------------------------------------+
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length
2 16 tcp.mp.subtype Subtype
2 20 tcp.mp.data Subtype-specific Data | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/transport/tcp.py#L686-L730 |
JarryShaw/PyPCAPKit | src/protocols/transport/tcp.py | TCP._read_mptcp_capable | def _read_mptcp_capable(self, bits, size, kind):
"""Read Multipath Capable option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Multipath Capable (MP_CAPABLE) option
Structure of MP_CAPABLE [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-------+---------------+
| Kind | Length |Subtype|Version|A|B|C|D|E|F|G|H|
+---------------+---------------+-------+-------+---------------+
| Option Sender's Key (64 bits) |
| |
| |
+---------------------------------------------------------------+
| Option Receiver's Key (64 bits) |
| (if option Length == 20) |
| |
+---------------------------------------------------------------+
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length (12/20)
2 16 tcp.mp.subtype Subtype (0)
2 20 tcp.mp.capable.version Version
3 24 tcp.mp.capable.flags.req Checksum Require Flag (A)
3 25 tcp.mp.capable.flags.ext Extensibility Flag (B)
3 26 tcp.mp.capable.flags.res Unassigned (C-G)
3 31 tcp.mp.capable.flags.hsa HMAC-SHA1 Flag (H)
4 32 tcp.mp.capable.skey Option Sender's Key
12 96 tcp.mp.capable.rkey Option Receiver's Key
(if option Length == 20)
"""
vers = int(bits, base=2)
bins = self._read_binary(1)
skey = self._read_fileng(8)
rkey = self._read_fileng(8) if size == 17 else None
data = dict(
kind=kind,
length=size + 1,
subtype='MP_CAPABLE',
capable=dict(
version=vers,
flags=dict(
req=True if int(bins[0]) else False,
ext=True if int(bins[1]) else False,
res=bytes(chr(int(bits[2:7], base=2)), encoding='utf-8'),
hsa=True if int(bins[7]) else False,
),
skey=skey,
rkey=rkey,
),
)
return data | python | def _read_mptcp_capable(self, bits, size, kind):
"""Read Multipath Capable option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Multipath Capable (MP_CAPABLE) option
Structure of MP_CAPABLE [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-------+---------------+
| Kind | Length |Subtype|Version|A|B|C|D|E|F|G|H|
+---------------+---------------+-------+-------+---------------+
| Option Sender's Key (64 bits) |
| |
| |
+---------------------------------------------------------------+
| Option Receiver's Key (64 bits) |
| (if option Length == 20) |
| |
+---------------------------------------------------------------+
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length (12/20)
2 16 tcp.mp.subtype Subtype (0)
2 20 tcp.mp.capable.version Version
3 24 tcp.mp.capable.flags.req Checksum Require Flag (A)
3 25 tcp.mp.capable.flags.ext Extensibility Flag (B)
3 26 tcp.mp.capable.flags.res Unassigned (C-G)
3 31 tcp.mp.capable.flags.hsa HMAC-SHA1 Flag (H)
4 32 tcp.mp.capable.skey Option Sender's Key
12 96 tcp.mp.capable.rkey Option Receiver's Key
(if option Length == 20)
"""
vers = int(bits, base=2)
bins = self._read_binary(1)
skey = self._read_fileng(8)
rkey = self._read_fileng(8) if size == 17 else None
data = dict(
kind=kind,
length=size + 1,
subtype='MP_CAPABLE',
capable=dict(
version=vers,
flags=dict(
req=True if int(bins[0]) else False,
ext=True if int(bins[1]) else False,
res=bytes(chr(int(bits[2:7], base=2)), encoding='utf-8'),
hsa=True if int(bins[7]) else False,
),
skey=skey,
rkey=rkey,
),
)
return data | Read Multipath Capable option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Multipath Capable (MP_CAPABLE) option
Structure of MP_CAPABLE [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-------+---------------+
| Kind | Length |Subtype|Version|A|B|C|D|E|F|G|H|
+---------------+---------------+-------+-------+---------------+
| Option Sender's Key (64 bits) |
| |
| |
+---------------------------------------------------------------+
| Option Receiver's Key (64 bits) |
| (if option Length == 20) |
| |
+---------------------------------------------------------------+
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length (12/20)
2 16 tcp.mp.subtype Subtype (0)
2 20 tcp.mp.capable.version Version
3 24 tcp.mp.capable.flags.req Checksum Require Flag (A)
3 25 tcp.mp.capable.flags.ext Extensibility Flag (B)
3 26 tcp.mp.capable.flags.res Unassigned (C-G)
3 31 tcp.mp.capable.flags.hsa HMAC-SHA1 Flag (H)
4 32 tcp.mp.capable.skey Option Sender's Key
12 96 tcp.mp.capable.rkey Option Receiver's Key
(if option Length == 20) | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/transport/tcp.py#L732-L794 |
JarryShaw/PyPCAPKit | src/protocols/transport/tcp.py | TCP._read_mptcp_join | def _read_mptcp_join(self, bits, size, kind):
"""Read Join Connection option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Join Connection (MP_JOIN) option
Structure of MP_JOIN [RFC 6824]:
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length
2 16 tcp.mp.subtype Subtype (1)
2 20 tcp.mp.data Handshake-specific Data
"""
if self._syn and self._ack: # MP_JOIN-SYN/ACK
return self._read_join_synack(bits, size, kind)
elif self._syn: # MP_JOIN-SYN
return self._read_join_syn(bits, size, kind)
elif self._ack: # MP_JOIN-ACK
return self._read_join_ack(bits, size, kind)
else: # illegal MP_JOIN occurred
temp = self._read_fileng(size)
data = dict(
kind=kind,
length=size + 1,
subtype='MP_JOIN-Unknown',
data=bytes(chr(int(bits[:4], base=2)), encoding='utf-8') + temp,
)
return data | python | def _read_mptcp_join(self, bits, size, kind):
"""Read Join Connection option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Join Connection (MP_JOIN) option
Structure of MP_JOIN [RFC 6824]:
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length
2 16 tcp.mp.subtype Subtype (1)
2 20 tcp.mp.data Handshake-specific Data
"""
if self._syn and self._ack: # MP_JOIN-SYN/ACK
return self._read_join_synack(bits, size, kind)
elif self._syn: # MP_JOIN-SYN
return self._read_join_syn(bits, size, kind)
elif self._ack: # MP_JOIN-ACK
return self._read_join_ack(bits, size, kind)
else: # illegal MP_JOIN occurred
temp = self._read_fileng(size)
data = dict(
kind=kind,
length=size + 1,
subtype='MP_JOIN-Unknown',
data=bytes(chr(int(bits[:4], base=2)), encoding='utf-8') + temp,
)
return data | Read Join Connection option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Join Connection (MP_JOIN) option
Structure of MP_JOIN [RFC 6824]:
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length
2 16 tcp.mp.subtype Subtype (1)
2 20 tcp.mp.data Handshake-specific Data | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/transport/tcp.py#L796-L829 |
JarryShaw/PyPCAPKit | src/protocols/transport/tcp.py | TCP._read_join_syn | def _read_join_syn(self, bits, size, kind):
"""Read Join Connection option for Initial SYN.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Join Connection (MP_JOIN-SYN) option for Initial SYN
Structure of MP_JOIN-SYN [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-----+-+---------------+
| Kind | Length = 12 |Subtype| |B| Address ID |
+---------------+---------------+-------+-----+-+---------------+
| Receiver's Token (32 bits) |
+---------------------------------------------------------------+
| Sender's Random Number (32 bits) |
+---------------------------------------------------------------+
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length (12)
2 16 tcp.mp.subtype Subtype (1|SYN)
2 20 - Reserved (must be zero)
2 23 tcp.mp.join.syn.backup Backup Path (B)
3 24 tcp.mp.join.syn.addrid Address ID
4 32 tcp.mp.join.syn.token Receiver's Token
8 64 tcp.mp.join.syn.randnum Sender's Random Number
"""
adid = self._read_unpack(1)
rtkn = self._read_fileng(4)
srno = self._read_unpack(4)
data = dict(
kind=kind,
length=size + 1,
subtype='MP_JOIN-SYN',
join=dict(
syn=dict(
backup=True if int(bits[3]) else False,
addrid=adid,
token=rtkn,
randnum=srno,
),
),
)
return data | python | def _read_join_syn(self, bits, size, kind):
"""Read Join Connection option for Initial SYN.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Join Connection (MP_JOIN-SYN) option for Initial SYN
Structure of MP_JOIN-SYN [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-----+-+---------------+
| Kind | Length = 12 |Subtype| |B| Address ID |
+---------------+---------------+-------+-----+-+---------------+
| Receiver's Token (32 bits) |
+---------------------------------------------------------------+
| Sender's Random Number (32 bits) |
+---------------------------------------------------------------+
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length (12)
2 16 tcp.mp.subtype Subtype (1|SYN)
2 20 - Reserved (must be zero)
2 23 tcp.mp.join.syn.backup Backup Path (B)
3 24 tcp.mp.join.syn.addrid Address ID
4 32 tcp.mp.join.syn.token Receiver's Token
8 64 tcp.mp.join.syn.randnum Sender's Random Number
"""
adid = self._read_unpack(1)
rtkn = self._read_fileng(4)
srno = self._read_unpack(4)
data = dict(
kind=kind,
length=size + 1,
subtype='MP_JOIN-SYN',
join=dict(
syn=dict(
backup=True if int(bits[3]) else False,
addrid=adid,
token=rtkn,
randnum=srno,
),
),
)
return data | Read Join Connection option for Initial SYN.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Join Connection (MP_JOIN-SYN) option for Initial SYN
Structure of MP_JOIN-SYN [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-----+-+---------------+
| Kind | Length = 12 |Subtype| |B| Address ID |
+---------------+---------------+-------+-----+-+---------------+
| Receiver's Token (32 bits) |
+---------------------------------------------------------------+
| Sender's Random Number (32 bits) |
+---------------------------------------------------------------+
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length (12)
2 16 tcp.mp.subtype Subtype (1|SYN)
2 20 - Reserved (must be zero)
2 23 tcp.mp.join.syn.backup Backup Path (B)
3 24 tcp.mp.join.syn.addrid Address ID
4 32 tcp.mp.join.syn.token Receiver's Token
8 64 tcp.mp.join.syn.randnum Sender's Random Number | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/transport/tcp.py#L831-L882 |
JarryShaw/PyPCAPKit | src/protocols/transport/tcp.py | TCP._read_join_synack | def _read_join_synack(self, bits, size, kind):
"""Read Join Connection option for Responding SYN/ACK.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Join Connection (MP_JOIN-SYN/ACK) option for Responding SYN/ACK
Structure of MP_JOIN-SYN/ACK [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-----+-+---------------+
| Kind | Length = 16 |Subtype| |B| Address ID |
+---------------+---------------+-------+-----+-+---------------+
| |
| Sender's Truncated HMAC (64 bits) |
| |
+---------------------------------------------------------------+
| Sender's Random Number (32 bits) |
+---------------------------------------------------------------+
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length (16)
2 16 tcp.mp.subtype Subtype (1|SYN/ACK)
2 20 - Reserved (must be zero)
2 23 tcp.mp.join.synack.backup Backup Path (B)
3 24 tcp.mp.join.synack.addrid Address ID
4 32 tcp.mp.join.synack.hmac Sender's Truncated HMAC
12 96 tcp.mp.join.synack.randnum Sender's Random Number
"""
adid = self._read_unpack(1)
hmac = self._read_fileng(8)
srno = self._read_unpack(4)
data = dict(
kind=kind,
length=size + 1,
subtype='MP_JOIN-SYN/ACK',
join=dict(
synack=dict(
backup=True if int(bits[3]) else False,
addrid=adid,
hmac=hmac,
randnum=srno,
),
),
)
return data | python | def _read_join_synack(self, bits, size, kind):
"""Read Join Connection option for Responding SYN/ACK.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Join Connection (MP_JOIN-SYN/ACK) option for Responding SYN/ACK
Structure of MP_JOIN-SYN/ACK [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-----+-+---------------+
| Kind | Length = 16 |Subtype| |B| Address ID |
+---------------+---------------+-------+-----+-+---------------+
| |
| Sender's Truncated HMAC (64 bits) |
| |
+---------------------------------------------------------------+
| Sender's Random Number (32 bits) |
+---------------------------------------------------------------+
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length (16)
2 16 tcp.mp.subtype Subtype (1|SYN/ACK)
2 20 - Reserved (must be zero)
2 23 tcp.mp.join.synack.backup Backup Path (B)
3 24 tcp.mp.join.synack.addrid Address ID
4 32 tcp.mp.join.synack.hmac Sender's Truncated HMAC
12 96 tcp.mp.join.synack.randnum Sender's Random Number
"""
adid = self._read_unpack(1)
hmac = self._read_fileng(8)
srno = self._read_unpack(4)
data = dict(
kind=kind,
length=size + 1,
subtype='MP_JOIN-SYN/ACK',
join=dict(
synack=dict(
backup=True if int(bits[3]) else False,
addrid=adid,
hmac=hmac,
randnum=srno,
),
),
)
return data | Read Join Connection option for Responding SYN/ACK.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Join Connection (MP_JOIN-SYN/ACK) option for Responding SYN/ACK
Structure of MP_JOIN-SYN/ACK [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-----+-+---------------+
| Kind | Length = 16 |Subtype| |B| Address ID |
+---------------+---------------+-------+-----+-+---------------+
| |
| Sender's Truncated HMAC (64 bits) |
| |
+---------------------------------------------------------------+
| Sender's Random Number (32 bits) |
+---------------------------------------------------------------+
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length (16)
2 16 tcp.mp.subtype Subtype (1|SYN/ACK)
2 20 - Reserved (must be zero)
2 23 tcp.mp.join.synack.backup Backup Path (B)
3 24 tcp.mp.join.synack.addrid Address ID
4 32 tcp.mp.join.synack.hmac Sender's Truncated HMAC
12 96 tcp.mp.join.synack.randnum Sender's Random Number | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/transport/tcp.py#L884-L937 |
JarryShaw/PyPCAPKit | src/protocols/transport/tcp.py | TCP._read_join_ack | def _read_join_ack(self, bits, size, kind):
"""Read Join Connection option for Third ACK.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Join Connection (MP_JOIN-ACK) option for Third ACK
Structure of MP_JOIN-ACK [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-----------------------+
| Kind | Length = 24 |Subtype| (reserved) |
+---------------+---------------+-------+-----------------------+
| |
| |
| Sender's HMAC (160 bits) |
| |
| |
+---------------------------------------------------------------+
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length (24)
2 16 tcp.mp.subtype Subtype (1|ACK)
2 20 - Reserved (must be zero)
4 32 tcp.mp.join.ack.hmac Sender's HMAC
"""
temp = self._read_fileng(20)
data = dict(
kind=kind,
length=size + 1,
subtype='MP_JOIN-ACK',
join=dict(
ack=dict(
hmac=temp,
),
),
)
return data | python | def _read_join_ack(self, bits, size, kind):
"""Read Join Connection option for Third ACK.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Join Connection (MP_JOIN-ACK) option for Third ACK
Structure of MP_JOIN-ACK [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-----------------------+
| Kind | Length = 24 |Subtype| (reserved) |
+---------------+---------------+-------+-----------------------+
| |
| |
| Sender's HMAC (160 bits) |
| |
| |
+---------------------------------------------------------------+
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length (24)
2 16 tcp.mp.subtype Subtype (1|ACK)
2 20 - Reserved (must be zero)
4 32 tcp.mp.join.ack.hmac Sender's HMAC
"""
temp = self._read_fileng(20)
data = dict(
kind=kind,
length=size + 1,
subtype='MP_JOIN-ACK',
join=dict(
ack=dict(
hmac=temp,
),
),
)
return data | Read Join Connection option for Third ACK.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Join Connection (MP_JOIN-ACK) option for Third ACK
Structure of MP_JOIN-ACK [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-----------------------+
| Kind | Length = 24 |Subtype| (reserved) |
+---------------+---------------+-------+-----------------------+
| |
| |
| Sender's HMAC (160 bits) |
| |
| |
+---------------------------------------------------------------+
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length (24)
2 16 tcp.mp.subtype Subtype (1|ACK)
2 20 - Reserved (must be zero)
4 32 tcp.mp.join.ack.hmac Sender's HMAC | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/transport/tcp.py#L939-L984 |
JarryShaw/PyPCAPKit | src/protocols/transport/tcp.py | TCP._read_mptcp_dss | def _read_mptcp_dss(self, bits, size, kind):
"""Read Data Sequence Signal (Data ACK and Data Sequence Mapping) option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Data Sequence Signal (DSS) option
Structure of DSS [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+----------------------+
| Kind | Length |Subtype| (reserved) |F|m|M|a|A|
+---------------+---------------+-------+----------------------+
| Data ACK (4 or 8 octets, depending on flags) |
+--------------------------------------------------------------+
| Data sequence number (4 or 8 octets, depending on flags) |
+--------------------------------------------------------------+
| Subflow Sequence Number (4 octets) |
+-------------------------------+------------------------------+
| Data-Level Length (2 octets) | Checksum (2 octets) |
+-------------------------------+------------------------------+
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+--------------------------------------------------------------+
| |
| Data Sequence Number (8 octets) |
| |
+--------------------------------------------------------------+
| Subflow Sequence Number (4 octets) |
+-------------------------------+------------------------------+
| Data-Level Length (2 octets) | Zeros (2 octets) |
+-------------------------------+------------------------------+
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length
2 16 tcp.mp.subtype Subtype (2)
2 20 - Reserved (must be zero)
3 27 tcp.mp.dss.flags.fin DATA_FIN (F)
3 28 tcp.mp.dss.flags.dsn_len DSN Length (m)
3 29 tcp.mp.dss.flags.data_pre DSN, SSN, Data-Level Length, CHKSUM Present (M)
3 30 tcp.mp.dss.flags.ack_len ACK Length (a)
3 31 tcp.mp.dss.flags.ack_pre Data ACK Present (A)
4 32 tcp.mp.dss.ack Data ACK (4/8 octets)
8-12 64-96 tcp.mp.dss.dsn DSN (4/8 octets)
12-20 48-160 tcp.mp.dss.ssn Subflow Sequence Number
16-24 128-192 tcp.mp.dss.dl_len Data-Level Length
18-26 144-208 tcp.mp.dss.checksum Checksum
"""
bits = self._read_binary(1)
mflg = 8 if int(bits[4]) else 4
Mflg = True if int(bits[5]) else False
aflg = 8 if int(bits[6]) else 4
Aflg = True if int(bits[7]) else False
ack_ = self._read_fileng(aflg) if Aflg else None
dsn_ = self._read_unpack(mflg) if Mflg else None
ssn_ = self._read_unpack(4) if Mflg else None
dll_ = self._read_unpack(2) if Mflg else None
chk_ = self._read_fileng(2) if Mflg else None
data = dict(
kind=kind,
length=size + 1,
subtype='DSS',
dss=dict(
flags=dict(
fin=True if int(bits[3]) else False,
dsn_len=mflg,
data_pre=Mflg,
ack_len=aflg,
ack_pre=Aflg,
),
ack=ack_,
dsn=dsn_,
ssn=ssn_,
dl_len=dll_,
checksum=chk_,
),
)
return data | python | def _read_mptcp_dss(self, bits, size, kind):
"""Read Data Sequence Signal (Data ACK and Data Sequence Mapping) option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Data Sequence Signal (DSS) option
Structure of DSS [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+----------------------+
| Kind | Length |Subtype| (reserved) |F|m|M|a|A|
+---------------+---------------+-------+----------------------+
| Data ACK (4 or 8 octets, depending on flags) |
+--------------------------------------------------------------+
| Data sequence number (4 or 8 octets, depending on flags) |
+--------------------------------------------------------------+
| Subflow Sequence Number (4 octets) |
+-------------------------------+------------------------------+
| Data-Level Length (2 octets) | Checksum (2 octets) |
+-------------------------------+------------------------------+
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+--------------------------------------------------------------+
| |
| Data Sequence Number (8 octets) |
| |
+--------------------------------------------------------------+
| Subflow Sequence Number (4 octets) |
+-------------------------------+------------------------------+
| Data-Level Length (2 octets) | Zeros (2 octets) |
+-------------------------------+------------------------------+
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length
2 16 tcp.mp.subtype Subtype (2)
2 20 - Reserved (must be zero)
3 27 tcp.mp.dss.flags.fin DATA_FIN (F)
3 28 tcp.mp.dss.flags.dsn_len DSN Length (m)
3 29 tcp.mp.dss.flags.data_pre DSN, SSN, Data-Level Length, CHKSUM Present (M)
3 30 tcp.mp.dss.flags.ack_len ACK Length (a)
3 31 tcp.mp.dss.flags.ack_pre Data ACK Present (A)
4 32 tcp.mp.dss.ack Data ACK (4/8 octets)
8-12 64-96 tcp.mp.dss.dsn DSN (4/8 octets)
12-20 48-160 tcp.mp.dss.ssn Subflow Sequence Number
16-24 128-192 tcp.mp.dss.dl_len Data-Level Length
18-26 144-208 tcp.mp.dss.checksum Checksum
"""
bits = self._read_binary(1)
mflg = 8 if int(bits[4]) else 4
Mflg = True if int(bits[5]) else False
aflg = 8 if int(bits[6]) else 4
Aflg = True if int(bits[7]) else False
ack_ = self._read_fileng(aflg) if Aflg else None
dsn_ = self._read_unpack(mflg) if Mflg else None
ssn_ = self._read_unpack(4) if Mflg else None
dll_ = self._read_unpack(2) if Mflg else None
chk_ = self._read_fileng(2) if Mflg else None
data = dict(
kind=kind,
length=size + 1,
subtype='DSS',
dss=dict(
flags=dict(
fin=True if int(bits[3]) else False,
dsn_len=mflg,
data_pre=Mflg,
ack_len=aflg,
ack_pre=Aflg,
),
ack=ack_,
dsn=dsn_,
ssn=ssn_,
dl_len=dll_,
checksum=chk_,
),
)
return data | Read Data Sequence Signal (Data ACK and Data Sequence Mapping) option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Data Sequence Signal (DSS) option
Structure of DSS [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+----------------------+
| Kind | Length |Subtype| (reserved) |F|m|M|a|A|
+---------------+---------------+-------+----------------------+
| Data ACK (4 or 8 octets, depending on flags) |
+--------------------------------------------------------------+
| Data sequence number (4 or 8 octets, depending on flags) |
+--------------------------------------------------------------+
| Subflow Sequence Number (4 octets) |
+-------------------------------+------------------------------+
| Data-Level Length (2 octets) | Checksum (2 octets) |
+-------------------------------+------------------------------+
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+--------------------------------------------------------------+
| |
| Data Sequence Number (8 octets) |
| |
+--------------------------------------------------------------+
| Subflow Sequence Number (4 octets) |
+-------------------------------+------------------------------+
| Data-Level Length (2 octets) | Zeros (2 octets) |
+-------------------------------+------------------------------+
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length
2 16 tcp.mp.subtype Subtype (2)
2 20 - Reserved (must be zero)
3 27 tcp.mp.dss.flags.fin DATA_FIN (F)
3 28 tcp.mp.dss.flags.dsn_len DSN Length (m)
3 29 tcp.mp.dss.flags.data_pre DSN, SSN, Data-Level Length, CHKSUM Present (M)
3 30 tcp.mp.dss.flags.ack_len ACK Length (a)
3 31 tcp.mp.dss.flags.ack_pre Data ACK Present (A)
4 32 tcp.mp.dss.ack Data ACK (4/8 octets)
8-12 64-96 tcp.mp.dss.dsn DSN (4/8 octets)
12-20 48-160 tcp.mp.dss.ssn Subflow Sequence Number
16-24 128-192 tcp.mp.dss.dl_len Data-Level Length
18-26 144-208 tcp.mp.dss.checksum Checksum | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/transport/tcp.py#L986-L1072 |
JarryShaw/PyPCAPKit | src/protocols/transport/tcp.py | TCP._read_mptcp_add | def _read_mptcp_add(self, bits, size, kind):
"""Read Add Address option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Add Address (ADD_ADDR) option
Structure of ADD_ADDR [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-------+---------------+
| Kind | Length |Subtype| IPVer | Address ID |
+---------------+---------------+-------+-------+---------------+
| Address (IPv4 - 4 octets / IPv6 - 16 octets) |
+-------------------------------+-------------------------------+
| Port (2 octets, optional) |
+-------------------------------+
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length
2 16 tcp.mp.subtype Subtype (3)
2 20 tcp.mp.addaddr.ipver IP Version
3 24 tcp.mp.addaddr.addrid Address ID
4 32 tcp.mp.addaddr.addr IP Address (4/16)
8-20 64-160 tcp.mp.addaddr.port Port (optional)
"""
vers = int(bits, base=2)
adid = self._read_unpack(1)
ipad = self._read_fileng(4) if vers == 4 else self._read_fileng(16)
ip_l = 4 if vers == 4 else 16
pt_l = size - 1 - ip_l
port = self._read_unpack(2) if pt_l else None
data = dict(
kind=kind,
length=size + 1,
subtype='ADD_ADDR',
addaddr=dict(
ipver=vers,
addrid=adid,
addr=ipaddress.ip_address(ipad),
port=port,
),
)
return data | python | def _read_mptcp_add(self, bits, size, kind):
"""Read Add Address option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Add Address (ADD_ADDR) option
Structure of ADD_ADDR [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-------+---------------+
| Kind | Length |Subtype| IPVer | Address ID |
+---------------+---------------+-------+-------+---------------+
| Address (IPv4 - 4 octets / IPv6 - 16 octets) |
+-------------------------------+-------------------------------+
| Port (2 octets, optional) |
+-------------------------------+
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length
2 16 tcp.mp.subtype Subtype (3)
2 20 tcp.mp.addaddr.ipver IP Version
3 24 tcp.mp.addaddr.addrid Address ID
4 32 tcp.mp.addaddr.addr IP Address (4/16)
8-20 64-160 tcp.mp.addaddr.port Port (optional)
"""
vers = int(bits, base=2)
adid = self._read_unpack(1)
ipad = self._read_fileng(4) if vers == 4 else self._read_fileng(16)
ip_l = 4 if vers == 4 else 16
pt_l = size - 1 - ip_l
port = self._read_unpack(2) if pt_l else None
data = dict(
kind=kind,
length=size + 1,
subtype='ADD_ADDR',
addaddr=dict(
ipver=vers,
addrid=adid,
addr=ipaddress.ip_address(ipad),
port=port,
),
)
return data | Read Add Address option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Add Address (ADD_ADDR) option
Structure of ADD_ADDR [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-------+---------------+
| Kind | Length |Subtype| IPVer | Address ID |
+---------------+---------------+-------+-------+---------------+
| Address (IPv4 - 4 octets / IPv6 - 16 octets) |
+-------------------------------+-------------------------------+
| Port (2 octets, optional) |
+-------------------------------+
Octets Bits Name Description
0 0 tcp.mp.kind Kind (30)
1 8 tcp.mp.length Length
2 16 tcp.mp.subtype Subtype (3)
2 20 tcp.mp.addaddr.ipver IP Version
3 24 tcp.mp.addaddr.addrid Address ID
4 32 tcp.mp.addaddr.addr IP Address (4/16)
8-20 64-160 tcp.mp.addaddr.port Port (optional) | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/transport/tcp.py#L1074-L1125 |
JarryShaw/PyPCAPKit | src/protocols/transport/tcp.py | TCP._read_mptcp_remove | def _read_mptcp_remove(self, bits, size):
"""Read Remove Address option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
Returns:
* dict -- extracted Remove Address (REMOVE_ADDR) option
Structure of REMOVE_ADDR [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-------+---------------+
| Kind | Length = 3+n |Subtype|(resvd)| Address ID | ...
+---------------+---------------+-------+-------+---------------+
(followed by n-1 Address IDs, if required)
Octets Bits Name Description
0 0 tcp.opt.kind Kind (30)
1 8 tcp.opt.length Length
2 16 tcp.opt.mp.subtype Subtype (4)
2 20 - Reserved (must be zero)
3 24 tcp.opt.mp.removeaddr.addrid Address ID (optional list)
"""
adid = []
for _ in size:
adid.append(self._read_unpack(1))
data = dict(
subtype='REMOVE_ADDR',
removeaddr=dict(
addrid=adid or None,
),
)
return data | python | def _read_mptcp_remove(self, bits, size):
"""Read Remove Address option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
Returns:
* dict -- extracted Remove Address (REMOVE_ADDR) option
Structure of REMOVE_ADDR [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-------+---------------+
| Kind | Length = 3+n |Subtype|(resvd)| Address ID | ...
+---------------+---------------+-------+-------+---------------+
(followed by n-1 Address IDs, if required)
Octets Bits Name Description
0 0 tcp.opt.kind Kind (30)
1 8 tcp.opt.length Length
2 16 tcp.opt.mp.subtype Subtype (4)
2 20 - Reserved (must be zero)
3 24 tcp.opt.mp.removeaddr.addrid Address ID (optional list)
"""
adid = []
for _ in size:
adid.append(self._read_unpack(1))
data = dict(
subtype='REMOVE_ADDR',
removeaddr=dict(
addrid=adid or None,
),
)
return data | Read Remove Address option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
Returns:
* dict -- extracted Remove Address (REMOVE_ADDR) option
Structure of REMOVE_ADDR [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-------+---------------+
| Kind | Length = 3+n |Subtype|(resvd)| Address ID | ...
+---------------+---------------+-------+-------+---------------+
(followed by n-1 Address IDs, if required)
Octets Bits Name Description
0 0 tcp.opt.kind Kind (30)
1 8 tcp.opt.length Length
2 16 tcp.opt.mp.subtype Subtype (4)
2 20 - Reserved (must be zero)
3 24 tcp.opt.mp.removeaddr.addrid Address ID (optional list) | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/transport/tcp.py#L1173-L1210 |
JarryShaw/PyPCAPKit | src/protocols/transport/tcp.py | TCP._read_mptcp_prio | def _read_mptcp_prio(self, bits, size):
"""Read Change Subflow Priority option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
Returns:
* dict -- extracted Change Subflow Priority (MP_PRIO) option
Structure of MP_PRIO [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-----+-+--------------+
| Kind | Length |Subtype| |B| AddrID (opt) |
+---------------+---------------+-------+-----+-+--------------+
Octets Bits Name Description
0 0 tcp.opt.kind Kind (30)
1 8 tcp.opt.length Length (3/4)
2 16 tcp.opt.mp.subtype Subtype (5)
2 23 tcp.opt.mp.prio.backup Backup Path (B)
3 24 tcp.opt.mp.prio.addrid Address ID (optional)
"""
temp = self._read_unpack(1) if size else None
data = dict(
subtype='MP_PRIO',
prio=dict(
res=b'\x00' * 3,
backup=True if int(bits[3]) else False,
addrid=temp,
),
)
return data | python | def _read_mptcp_prio(self, bits, size):
"""Read Change Subflow Priority option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
Returns:
* dict -- extracted Change Subflow Priority (MP_PRIO) option
Structure of MP_PRIO [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-----+-+--------------+
| Kind | Length |Subtype| |B| AddrID (opt) |
+---------------+---------------+-------+-----+-+--------------+
Octets Bits Name Description
0 0 tcp.opt.kind Kind (30)
1 8 tcp.opt.length Length (3/4)
2 16 tcp.opt.mp.subtype Subtype (5)
2 23 tcp.opt.mp.prio.backup Backup Path (B)
3 24 tcp.opt.mp.prio.addrid Address ID (optional)
"""
temp = self._read_unpack(1) if size else None
data = dict(
subtype='MP_PRIO',
prio=dict(
res=b'\x00' * 3,
backup=True if int(bits[3]) else False,
addrid=temp,
),
)
return data | Read Change Subflow Priority option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
Returns:
* dict -- extracted Change Subflow Priority (MP_PRIO) option
Structure of MP_PRIO [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-----+-+--------------+
| Kind | Length |Subtype| |B| AddrID (opt) |
+---------------+---------------+-------+-----+-+--------------+
Octets Bits Name Description
0 0 tcp.opt.kind Kind (30)
1 8 tcp.opt.length Length (3/4)
2 16 tcp.opt.mp.subtype Subtype (5)
2 23 tcp.opt.mp.prio.backup Backup Path (B)
3 24 tcp.opt.mp.prio.addrid Address ID (optional) | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/transport/tcp.py#L1212-L1248 |
JarryShaw/PyPCAPKit | src/protocols/transport/tcp.py | TCP._read_mptcp_fail | def _read_mptcp_fail(self, bits, size):
"""Read Fallback option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
Returns:
* dict -- extracted Fallback (MP_FAIL) option
Structure of MP_FAIL [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+----------------------+
| Kind | Length=12 |Subtype| (reserved) |
+---------------+---------------+-------+----------------------+
| |
| Data Sequence Number (8 octets) |
| |
+--------------------------------------------------------------+
Octets Bits Name Description
0 0 tcp.opt.kind Kind (30)
1 8 tcp.opt.length Length (12)
2 16 tcp.opt.mp.subtype Subtype (6)
2 23 - Reserved (must be zero)
4 32 tcp.opt.mp.fail.dsn Data Sequence Number
"""
____ = self._read_fileng(1)
dsn_ = self._read_unpack(8)
data = dict(
subtype='MP_FAIL',
fail=dict(
dsn=dsn_,
),
)
return data | python | def _read_mptcp_fail(self, bits, size):
"""Read Fallback option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
Returns:
* dict -- extracted Fallback (MP_FAIL) option
Structure of MP_FAIL [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+----------------------+
| Kind | Length=12 |Subtype| (reserved) |
+---------------+---------------+-------+----------------------+
| |
| Data Sequence Number (8 octets) |
| |
+--------------------------------------------------------------+
Octets Bits Name Description
0 0 tcp.opt.kind Kind (30)
1 8 tcp.opt.length Length (12)
2 16 tcp.opt.mp.subtype Subtype (6)
2 23 - Reserved (must be zero)
4 32 tcp.opt.mp.fail.dsn Data Sequence Number
"""
____ = self._read_fileng(1)
dsn_ = self._read_unpack(8)
data = dict(
subtype='MP_FAIL',
fail=dict(
dsn=dsn_,
),
)
return data | Read Fallback option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
Returns:
* dict -- extracted Fallback (MP_FAIL) option
Structure of MP_FAIL [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+----------------------+
| Kind | Length=12 |Subtype| (reserved) |
+---------------+---------------+-------+----------------------+
| |
| Data Sequence Number (8 octets) |
| |
+--------------------------------------------------------------+
Octets Bits Name Description
0 0 tcp.opt.kind Kind (30)
1 8 tcp.opt.length Length (12)
2 16 tcp.opt.mp.subtype Subtype (6)
2 23 - Reserved (must be zero)
4 32 tcp.opt.mp.fail.dsn Data Sequence Number | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/transport/tcp.py#L1250-L1289 |
JarryShaw/PyPCAPKit | src/protocols/transport/tcp.py | TCP._read_mptcp_fastclose | def _read_mptcp_fastclose(self, bits, size):
"""Read Fast Close option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
Returns:
* dict -- extracted Fast Close (MP_FASTCLOSE) option
Structure of MP_FASTCLOSE [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-----------------------+
| Kind | Length |Subtype| (reserved) |
+---------------+---------------+-------+-----------------------+
| Option Receiver's Key |
| (64 bits) |
| |
+---------------------------------------------------------------+
Octets Bits Name Description
0 0 tcp.opt.kind Kind (30)
1 8 tcp.opt.length Length (12)
2 16 tcp.opt.mp.subtype Subtype (7)
2 23 - Reserved (must be zero)
4 32 tcp.opt.mp.fastclose.rkey Option Receiver's Key
"""
____ = self._read_fileng(1)
rkey = self._read_fileng(8)
data = dict(
subtype='MP_FASTCLOSE',
fastclose=dict(
rkey=rkey,
),
)
return data | python | def _read_mptcp_fastclose(self, bits, size):
"""Read Fast Close option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
Returns:
* dict -- extracted Fast Close (MP_FASTCLOSE) option
Structure of MP_FASTCLOSE [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-----------------------+
| Kind | Length |Subtype| (reserved) |
+---------------+---------------+-------+-----------------------+
| Option Receiver's Key |
| (64 bits) |
| |
+---------------------------------------------------------------+
Octets Bits Name Description
0 0 tcp.opt.kind Kind (30)
1 8 tcp.opt.length Length (12)
2 16 tcp.opt.mp.subtype Subtype (7)
2 23 - Reserved (must be zero)
4 32 tcp.opt.mp.fastclose.rkey Option Receiver's Key
"""
____ = self._read_fileng(1)
rkey = self._read_fileng(8)
data = dict(
subtype='MP_FASTCLOSE',
fastclose=dict(
rkey=rkey,
),
)
return data | Read Fast Close option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
Returns:
* dict -- extracted Fast Close (MP_FASTCLOSE) option
Structure of MP_FASTCLOSE [RFC 6824]:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-----------------------+
| Kind | Length |Subtype| (reserved) |
+---------------+---------------+-------+-----------------------+
| Option Receiver's Key |
| (64 bits) |
| |
+---------------------------------------------------------------+
Octets Bits Name Description
0 0 tcp.opt.kind Kind (30)
1 8 tcp.opt.length Length (12)
2 16 tcp.opt.mp.subtype Subtype (7)
2 23 - Reserved (must be zero)
4 32 tcp.opt.mp.fastclose.rkey Option Receiver's Key | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/transport/tcp.py#L1291-L1330 |
JarryShaw/PyPCAPKit | src/const/hip/esp_transform_suite.py | ESP_TransformSuite.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return ESP_TransformSuite(key)
if key not in ESP_TransformSuite._member_map_:
extend_enum(ESP_TransformSuite, key, default)
return ESP_TransformSuite[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return ESP_TransformSuite(key)
if key not in ESP_TransformSuite._member_map_:
extend_enum(ESP_TransformSuite, key, default)
return ESP_TransformSuite[key] | Backport support for original codes. | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/hip/esp_transform_suite.py#L30-L36 |
JarryShaw/PyPCAPKit | src/const/ipv4/classification_level.py | ClassificationLevel.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return ClassificationLevel(key)
if key not in ClassificationLevel._member_map_:
extend_enum(ClassificationLevel, key, default)
return ClassificationLevel[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return ClassificationLevel(key)
if key not in ClassificationLevel._member_map_:
extend_enum(ClassificationLevel, key, default)
return ClassificationLevel[key] | Backport support for original codes. | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/ipv4/classification_level.py#L22-L28 |
JarryShaw/PyPCAPKit | src/interface/__init__.py | extract | def extract(fin=None, fout=None, format=None, # basic settings
auto=True, extension=True, store=True, # internal settings
files=False, nofile=False, verbose=False, # output settings
engine=None, layer=None, protocol=None, # extraction settings
ip=False, ipv4=False, ipv6=False, tcp=False, strict=True, # reassembly settings
trace=False, trace_fout=None, trace_format=None, # trace settings
trace_byteorder=sys.byteorder, trace_nanosecond=False): # trace settings
"""Extract a PCAP file.
Keyword arguments:
* fin -- str, file name to be read; if file not exist, raise an error
* fout -- str, file name to be written
* format -- str, file format of output
<keyword> 'plist' / 'json' / 'tree' / 'html'
* auto -- bool, if automatically run till EOF (default is True)
<keyword> True / False
* extension -- bool, if check and append extensions to output file (default is True)
<keyword> True / False
* store -- bool, if store extracted packet info (default is True)
<keyword> True / False
* files -- bool, if split each frame into different files (default is False)
<keyword> True / False
* nofile -- bool, if no output file is to be dumped (default is False)
<keyword> True / False
* verbose -- bool, if print verbose output information (default is False)
<keyword> True / False
* engine -- str, extraction engine to be used
<keyword> 'default | pcapkit'
* layer -- str, extract til which layer
<keyword> 'Link' / 'Internet' / 'Transport' / 'Application'
* protocol -- str, extract til which protocol
<keyword> available protocol name
* ip -- bool, if record data for IPv4 & IPv6 reassembly (default is False)
<keyword> True / False
* ipv4 -- bool, if perform IPv4 reassembly (default is False)
<keyword> True / False
* ipv6 -- bool, if perform IPv6 reassembly (default is False)
<keyword> True / False
* tcp -- bool, if perform TCP reassembly (default is False)
<keyword> True / False
* strict -- bool, if set strict flag for reassembly (default is True)
<keyword> True / False
* trace -- bool, if trace TCP traffic flows (default is False)
<keyword> True / False
* trace_fout -- str, path name for flow tracer if necessary
* trace_format -- str, output file format of flow tracer
<keyword> 'plist' / 'json' / 'tree' / 'html' / 'pcap'
* trace_byteorder -- str, output file byte order
<keyword> 'little' / 'big'
* trace_nanosecond -- bool, output nanosecond-resolution file flag
<keyword> True / False
Returns:
* Extractor -- an Extractor object form `pcapkit.extractor`
"""
if isinstance(layer, type) and issubclass(layer, Protocol):
layer = layer.__layer__
if isinstance(protocol, type) and issubclass(protocol, Protocol):
protocol = protocol.__index__()
str_check(fin or '', fout or '', format or '',
trace_fout or '', trace_format or '',
engine or '', layer or '', *(protocol or ''))
bool_check(files, nofile, verbose, auto, extension, store,
ip, ipv4, ipv6, tcp, strict, trace)
return Extractor(fin=fin, fout=fout, format=format,
store=store, files=files, nofile=nofile,
auto=auto, verbose=verbose, extension=extension,
engine=engine, layer=layer, protocol=protocol,
ip=ip, ipv4=ipv4, ipv6=ipv6, tcp=tcp, strict=strict,
trace=trace, trace_fout=trace_fout, trace_format=trace_format,
trace_byteorder=trace_byteorder, trace_nanosecond=trace_nanosecond) | python | def extract(fin=None, fout=None, format=None, # basic settings
auto=True, extension=True, store=True, # internal settings
files=False, nofile=False, verbose=False, # output settings
engine=None, layer=None, protocol=None, # extraction settings
ip=False, ipv4=False, ipv6=False, tcp=False, strict=True, # reassembly settings
trace=False, trace_fout=None, trace_format=None, # trace settings
trace_byteorder=sys.byteorder, trace_nanosecond=False): # trace settings
"""Extract a PCAP file.
Keyword arguments:
* fin -- str, file name to be read; if file not exist, raise an error
* fout -- str, file name to be written
* format -- str, file format of output
<keyword> 'plist' / 'json' / 'tree' / 'html'
* auto -- bool, if automatically run till EOF (default is True)
<keyword> True / False
* extension -- bool, if check and append extensions to output file (default is True)
<keyword> True / False
* store -- bool, if store extracted packet info (default is True)
<keyword> True / False
* files -- bool, if split each frame into different files (default is False)
<keyword> True / False
* nofile -- bool, if no output file is to be dumped (default is False)
<keyword> True / False
* verbose -- bool, if print verbose output information (default is False)
<keyword> True / False
* engine -- str, extraction engine to be used
<keyword> 'default | pcapkit'
* layer -- str, extract til which layer
<keyword> 'Link' / 'Internet' / 'Transport' / 'Application'
* protocol -- str, extract til which protocol
<keyword> available protocol name
* ip -- bool, if record data for IPv4 & IPv6 reassembly (default is False)
<keyword> True / False
* ipv4 -- bool, if perform IPv4 reassembly (default is False)
<keyword> True / False
* ipv6 -- bool, if perform IPv6 reassembly (default is False)
<keyword> True / False
* tcp -- bool, if perform TCP reassembly (default is False)
<keyword> True / False
* strict -- bool, if set strict flag for reassembly (default is True)
<keyword> True / False
* trace -- bool, if trace TCP traffic flows (default is False)
<keyword> True / False
* trace_fout -- str, path name for flow tracer if necessary
* trace_format -- str, output file format of flow tracer
<keyword> 'plist' / 'json' / 'tree' / 'html' / 'pcap'
* trace_byteorder -- str, output file byte order
<keyword> 'little' / 'big'
* trace_nanosecond -- bool, output nanosecond-resolution file flag
<keyword> True / False
Returns:
* Extractor -- an Extractor object form `pcapkit.extractor`
"""
if isinstance(layer, type) and issubclass(layer, Protocol):
layer = layer.__layer__
if isinstance(protocol, type) and issubclass(protocol, Protocol):
protocol = protocol.__index__()
str_check(fin or '', fout or '', format or '',
trace_fout or '', trace_format or '',
engine or '', layer or '', *(protocol or ''))
bool_check(files, nofile, verbose, auto, extension, store,
ip, ipv4, ipv6, tcp, strict, trace)
return Extractor(fin=fin, fout=fout, format=format,
store=store, files=files, nofile=nofile,
auto=auto, verbose=verbose, extension=extension,
engine=engine, layer=layer, protocol=protocol,
ip=ip, ipv4=ipv4, ipv6=ipv6, tcp=tcp, strict=strict,
trace=trace, trace_fout=trace_fout, trace_format=trace_format,
trace_byteorder=trace_byteorder, trace_nanosecond=trace_nanosecond) | Extract a PCAP file.
Keyword arguments:
* fin -- str, file name to be read; if file not exist, raise an error
* fout -- str, file name to be written
* format -- str, file format of output
<keyword> 'plist' / 'json' / 'tree' / 'html'
* auto -- bool, if automatically run till EOF (default is True)
<keyword> True / False
* extension -- bool, if check and append extensions to output file (default is True)
<keyword> True / False
* store -- bool, if store extracted packet info (default is True)
<keyword> True / False
* files -- bool, if split each frame into different files (default is False)
<keyword> True / False
* nofile -- bool, if no output file is to be dumped (default is False)
<keyword> True / False
* verbose -- bool, if print verbose output information (default is False)
<keyword> True / False
* engine -- str, extraction engine to be used
<keyword> 'default | pcapkit'
* layer -- str, extract til which layer
<keyword> 'Link' / 'Internet' / 'Transport' / 'Application'
* protocol -- str, extract til which protocol
<keyword> available protocol name
* ip -- bool, if record data for IPv4 & IPv6 reassembly (default is False)
<keyword> True / False
* ipv4 -- bool, if perform IPv4 reassembly (default is False)
<keyword> True / False
* ipv6 -- bool, if perform IPv6 reassembly (default is False)
<keyword> True / False
* tcp -- bool, if perform TCP reassembly (default is False)
<keyword> True / False
* strict -- bool, if set strict flag for reassembly (default is True)
<keyword> True / False
* trace -- bool, if trace TCP traffic flows (default is False)
<keyword> True / False
* trace_fout -- str, path name for flow tracer if necessary
* trace_format -- str, output file format of flow tracer
<keyword> 'plist' / 'json' / 'tree' / 'html' / 'pcap'
* trace_byteorder -- str, output file byte order
<keyword> 'little' / 'big'
* trace_nanosecond -- bool, output nanosecond-resolution file flag
<keyword> True / False
Returns:
* Extractor -- an Extractor object form `pcapkit.extractor` | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/interface/__init__.py#L53-L131 |
JarryShaw/PyPCAPKit | src/interface/__init__.py | analyse | def analyse(file, length=None):
"""Analyse application layer packets.
Keyword arguments:
* file -- bytes or file-like object, packet to be analysed
* length -- int, length of the analysing packet
Returns:
* Analysis -- an Analysis object from `pcapkit.analyser`
"""
if isinstance(file, bytes):
file = io.BytesIO(file)
io_check(file)
int_check(length or sys.maxsize)
return analyse2(file, length) | python | def analyse(file, length=None):
"""Analyse application layer packets.
Keyword arguments:
* file -- bytes or file-like object, packet to be analysed
* length -- int, length of the analysing packet
Returns:
* Analysis -- an Analysis object from `pcapkit.analyser`
"""
if isinstance(file, bytes):
file = io.BytesIO(file)
io_check(file)
int_check(length or sys.maxsize)
return analyse2(file, length) | Analyse application layer packets.
Keyword arguments:
* file -- bytes or file-like object, packet to be analysed
* length -- int, length of the analysing packet
Returns:
* Analysis -- an Analysis object from `pcapkit.analyser` | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/interface/__init__.py#L134-L151 |
JarryShaw/PyPCAPKit | src/interface/__init__.py | reassemble | def reassemble(protocol, strict=False):
"""Reassemble fragmented datagrams.
Keyword arguments:
* protocol -- str, protocol to be reassembled
* strict -- bool, if return all datagrams (including those not implemented) when submit (default is False)
<keyword> True / False
Returns:
* [if protocol is IPv4] IPv4_Reassembly -- a Reassembly object from `pcapkit.reassembly`
* [if protocol is IPv6] IPv6_Reassembly -- a Reassembly object from `pcapkit.reassembly`
* [if protocol is TCP] TCP_Reassembly -- a Reassembly object from `pcapkit.reassembly`
"""
if isinstance(protocol, type) and issubclass(protocol, Protocol):
protocol = protocol.__index__()
str_check(protocol)
bool_check(strict)
if protocol == 'IPv4':
return IPv4_Reassembly(strict=strict)
elif protocol == 'IPv6':
return IPv6_Reassembly(strict=strict)
elif protocol == 'TCP':
return TCP_Reassembly(strict=strict)
else:
raise FormatError(f'Unsupported reassembly protocol: {protocol}') | python | def reassemble(protocol, strict=False):
"""Reassemble fragmented datagrams.
Keyword arguments:
* protocol -- str, protocol to be reassembled
* strict -- bool, if return all datagrams (including those not implemented) when submit (default is False)
<keyword> True / False
Returns:
* [if protocol is IPv4] IPv4_Reassembly -- a Reassembly object from `pcapkit.reassembly`
* [if protocol is IPv6] IPv6_Reassembly -- a Reassembly object from `pcapkit.reassembly`
* [if protocol is TCP] TCP_Reassembly -- a Reassembly object from `pcapkit.reassembly`
"""
if isinstance(protocol, type) and issubclass(protocol, Protocol):
protocol = protocol.__index__()
str_check(protocol)
bool_check(strict)
if protocol == 'IPv4':
return IPv4_Reassembly(strict=strict)
elif protocol == 'IPv6':
return IPv6_Reassembly(strict=strict)
elif protocol == 'TCP':
return TCP_Reassembly(strict=strict)
else:
raise FormatError(f'Unsupported reassembly protocol: {protocol}') | Reassemble fragmented datagrams.
Keyword arguments:
* protocol -- str, protocol to be reassembled
* strict -- bool, if return all datagrams (including those not implemented) when submit (default is False)
<keyword> True / False
Returns:
* [if protocol is IPv4] IPv4_Reassembly -- a Reassembly object from `pcapkit.reassembly`
* [if protocol is IPv6] IPv6_Reassembly -- a Reassembly object from `pcapkit.reassembly`
* [if protocol is TCP] TCP_Reassembly -- a Reassembly object from `pcapkit.reassembly` | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/interface/__init__.py#L154-L181 |
JarryShaw/PyPCAPKit | src/interface/__init__.py | trace | def trace(fout=None, format=None, byteorder=sys.byteorder, nanosecond=False):
"""Trace TCP flows.
Keyword arguments:
* fout -- str, output path
* format -- str, output format
* byteorder -- str, output file byte order
* nanosecond -- bool, output nanosecond-resolution file flag
"""
str_check(fout or '', format or '')
return TraceFlow(fout=fout, format=format, byteorder=byteorder, nanosecond=nanosecond) | python | def trace(fout=None, format=None, byteorder=sys.byteorder, nanosecond=False):
"""Trace TCP flows.
Keyword arguments:
* fout -- str, output path
* format -- str, output format
* byteorder -- str, output file byte order
* nanosecond -- bool, output nanosecond-resolution file flag
"""
str_check(fout or '', format or '')
return TraceFlow(fout=fout, format=format, byteorder=byteorder, nanosecond=nanosecond) | Trace TCP flows.
Keyword arguments:
* fout -- str, output path
* format -- str, output format
* byteorder -- str, output file byte order
* nanosecond -- bool, output nanosecond-resolution file flag | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/interface/__init__.py#L184-L195 |
JarryShaw/PyPCAPKit | src/const/misc/transtype.py | TransType.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return TransType(key)
if key not in TransType._member_map_:
extend_enum(TransType, key, default)
return TransType[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return TransType(key)
if key not in TransType._member_map_:
extend_enum(TransType, key, default)
return TransType[key] | Backport support for original codes. | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/misc/transtype.py#L161-L167 |
JarryShaw/PyPCAPKit | src/protocols/internet/ipv6_frag.py | IPv6_Frag.read_ipv6_frag | def read_ipv6_frag(self, length, extension):
"""Read Fragment Header for IPv6.
Structure of IPv6-Frag header [RFC 8200]:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Header | Reserved | Fragment Offset |Res|M|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identification |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 frag.next Next Header
1 8 - Reserved
2 16 frag.offset Fragment Offset
3 29 - Reserved
3 31 frag.mf More Flag
4 32 frag.id Identification
"""
if length is None:
length = len(self)
_next = self._read_protos(1)
_temp = self._read_fileng(1)
_offm = self._read_binary(2)
_ipid = self._read_unpack(4)
ipv6_frag = dict(
next=_next,
length=8,
offset=int(_offm[:13], base=2),
mf=True if int(_offm[15], base=2) else False,
id=_ipid,
)
length -= ipv6_frag['length']
ipv6_frag['packet'] = self._read_packet(header=8, payload=length)
if extension:
self._protos = None
return ipv6_frag
return self._decode_next_layer(ipv6_frag, _next, length) | python | def read_ipv6_frag(self, length, extension):
"""Read Fragment Header for IPv6.
Structure of IPv6-Frag header [RFC 8200]:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Header | Reserved | Fragment Offset |Res|M|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identification |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 frag.next Next Header
1 8 - Reserved
2 16 frag.offset Fragment Offset
3 29 - Reserved
3 31 frag.mf More Flag
4 32 frag.id Identification
"""
if length is None:
length = len(self)
_next = self._read_protos(1)
_temp = self._read_fileng(1)
_offm = self._read_binary(2)
_ipid = self._read_unpack(4)
ipv6_frag = dict(
next=_next,
length=8,
offset=int(_offm[:13], base=2),
mf=True if int(_offm[15], base=2) else False,
id=_ipid,
)
length -= ipv6_frag['length']
ipv6_frag['packet'] = self._read_packet(header=8, payload=length)
if extension:
self._protos = None
return ipv6_frag
return self._decode_next_layer(ipv6_frag, _next, length) | Read Fragment Header for IPv6.
Structure of IPv6-Frag header [RFC 8200]:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Header | Reserved | Fragment Offset |Res|M|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identification |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 frag.next Next Header
1 8 - Reserved
2 16 frag.offset Fragment Offset
3 29 - Reserved
3 31 frag.mf More Flag
4 32 frag.id Identification | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/ipv6_frag.py#L87-L128 |
JarryShaw/PyPCAPKit | src/const/hip/hi_algorithm.py | HI_Algorithm.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return HI_Algorithm(key)
if key not in HI_Algorithm._member_map_:
extend_enum(HI_Algorithm, key, default)
return HI_Algorithm[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return HI_Algorithm(key)
if key not in HI_Algorithm._member_map_:
extend_enum(HI_Algorithm, key, default)
return HI_Algorithm[key] | Backport support for original codes. | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/hip/hi_algorithm.py#L24-L30 |
JarryShaw/PyPCAPKit | src/const/hip/parameter.py | Parameter.get | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return Parameter(key)
if key not in Parameter._member_map_:
extend_enum(Parameter, key, default)
return Parameter[key] | python | def get(key, default=-1):
"""Backport support for original codes."""
if isinstance(key, int):
return Parameter(key)
if key not in Parameter._member_map_:
extend_enum(Parameter, key, default)
return Parameter[key] | Backport support for original codes. | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/hip/parameter.py#L71-L77 |
JarryShaw/PyPCAPKit | src/const/hip/parameter.py | Parameter._missing_ | def _missing_(cls, value):
"""Lookup function used when value is not found."""
if not (isinstance(value, int) and 0 <= value <= 65535):
raise ValueError('%r is not a valid %s' % (value, cls.__name__))
if 0 <= value <= 64:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 66 <= value <= 127:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 130 <= value <= 192:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 194 <= value <= 256:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 258 <= value <= 320:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 322 <= value <= 384:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 386 <= value <= 448:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 450 <= value <= 510:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 514 <= value <= 576:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 580 <= value <= 607:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 611 <= value <= 640:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 642 <= value <= 704:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 706 <= value <= 714:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 716 <= value <= 767:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 769 <= value <= 831:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 833 <= value <= 896:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 898 <= value <= 929:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 937 <= value <= 949:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 951 <= value <= 960:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 962 <= value <= 2048:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 2050 <= value <= 4094:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 4096 <= value <= 4480:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 4482 <= value <= 4544:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 4546 <= value <= 4576:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 4578 <= value <= 4579:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 4581 <= value <= 4591:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 4593 <= value <= 4600:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 4602 <= value <= 7679:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 7681 <= value <= 32767:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 32768 <= value <= 49151:
# [RFC 7401]
extend_enum(cls, 'Reserved [%d]' % value, value)
return cls(value)
if 49152 <= value <= 61504:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 61506 <= value <= 61568:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 61570 <= value <= 61632:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 61634 <= value <= 61696:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 61698 <= value <= 63660:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 63662 <= value <= 63424:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 63426 <= value <= 63997:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 63999 <= value <= 64001:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 64003 <= value <= 64010:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 64012 <= value <= 64016:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 64018 <= value <= 65497:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 65503 <= value <= 65519:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 65521 <= value <= 65535:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
super()._missing_(value) | python | def _missing_(cls, value):
"""Lookup function used when value is not found."""
if not (isinstance(value, int) and 0 <= value <= 65535):
raise ValueError('%r is not a valid %s' % (value, cls.__name__))
if 0 <= value <= 64:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 66 <= value <= 127:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 130 <= value <= 192:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 194 <= value <= 256:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 258 <= value <= 320:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 322 <= value <= 384:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 386 <= value <= 448:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 450 <= value <= 510:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 514 <= value <= 576:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 580 <= value <= 607:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 611 <= value <= 640:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 642 <= value <= 704:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 706 <= value <= 714:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 716 <= value <= 767:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 769 <= value <= 831:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 833 <= value <= 896:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 898 <= value <= 929:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 937 <= value <= 949:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 951 <= value <= 960:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 962 <= value <= 2048:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 2050 <= value <= 4094:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 4096 <= value <= 4480:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 4482 <= value <= 4544:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 4546 <= value <= 4576:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 4578 <= value <= 4579:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 4581 <= value <= 4591:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 4593 <= value <= 4600:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 4602 <= value <= 7679:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 7681 <= value <= 32767:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 32768 <= value <= 49151:
# [RFC 7401]
extend_enum(cls, 'Reserved [%d]' % value, value)
return cls(value)
if 49152 <= value <= 61504:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 61506 <= value <= 61568:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 61570 <= value <= 61632:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 61634 <= value <= 61696:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 61698 <= value <= 63660:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 63662 <= value <= 63424:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 63426 <= value <= 63997:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 63999 <= value <= 64001:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 64003 <= value <= 64010:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 64012 <= value <= 64016:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 64018 <= value <= 65497:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 65503 <= value <= 65519:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 65521 <= value <= 65535:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
super()._missing_(value) | Lookup function used when value is not found. | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/const/hip/parameter.py#L80-L214 |
JarryShaw/PyPCAPKit | src/protocols/internet/ipv4.py | IPv4.read_ipv4 | def read_ipv4(self, length):
"""Read Internet Protocol version 4 (IPv4).
Structure of IPv4 header [RFC 791]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version| IHL |Type of Service| Total Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identification |Flags| Fragment Offset |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Time to Live | Protocol | Header Checksum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Destination Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 ip.version Version (4)
0 4 ip.hdr_len Internal Header Length (IHL)
1 8 ip.dsfield.dscp Differentiated Services Code Point (DSCP)
1 14 ip.dsfield.ecn Explicit Congestion Notification (ECN)
2 16 ip.len Total Length
4 32 ip.id Identification
6 48 - Reserved Bit (must be zero)
6 49 ip.flags.df Don't Fragment (DF)
6 50 ip.flags.mf More Fragments (MF)
6 51 ip.frag_offset Fragment Offset
8 64 ip.ttl Time To Live (TTL)
9 72 ip.proto Protocol (Transport Layer)
10 80 ip.checksum Header Checksum
12 96 ip.src Source IP Address
16 128 ip.dst Destination IP Address
20 160 ip.options IP Options (if IHL > 5)
"""
if length is None:
length = len(self)
_vihl = self._read_fileng(1).hex()
_dscp = self._read_binary(1)
_tlen = self._read_unpack(2)
_iden = self._read_unpack(2)
_frag = self._read_binary(2)
_ttol = self._read_unpack(1)
_prot = self._read_protos(1)
_csum = self._read_fileng(2)
_srca = self._read_ipv4_addr()
_dsta = self._read_ipv4_addr()
ipv4 = dict(
version=_vihl[0],
hdr_len=int(_vihl[1], base=16) * 4,
dsfield=dict(
dscp=(
TOS_PRE.get(int(_dscp[:3], base=2)),
TOS_DEL.get(int(_dscp[3], base=2)),
TOS_THR.get(int(_dscp[4], base=2)),
TOS_REL.get(int(_dscp[5], base=2)),
),
ecn=TOS_ECN.get(int(_dscp[-2:], base=2)),
),
len=_tlen,
id=_iden,
flags=dict(
df=True if int(_frag[1]) else False,
mf=True if int(_frag[2]) else False,
),
frag_offset=int(_frag[3:], base=2) * 8,
ttl=_ttol,
proto=_prot,
checksum=_csum,
src=_srca,
dst=_dsta,
)
_optl = ipv4['hdr_len'] - 20
if _optl:
options = self._read_ipv4_options(_optl)
ipv4['opt'] = options[0] # tuple of option acronyms
ipv4.update(options[1]) # merge option info to buffer
# ipv4['opt'] = self._read_fileng(_optl) or None
hdr_len = ipv4['hdr_len']
raw_len = ipv4['len'] - hdr_len
ipv4['packet'] = self._read_packet(header=hdr_len, payload=raw_len)
return self._decode_next_layer(ipv4, _prot, raw_len) | python | def read_ipv4(self, length):
"""Read Internet Protocol version 4 (IPv4).
Structure of IPv4 header [RFC 791]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version| IHL |Type of Service| Total Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identification |Flags| Fragment Offset |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Time to Live | Protocol | Header Checksum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Destination Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 ip.version Version (4)
0 4 ip.hdr_len Internal Header Length (IHL)
1 8 ip.dsfield.dscp Differentiated Services Code Point (DSCP)
1 14 ip.dsfield.ecn Explicit Congestion Notification (ECN)
2 16 ip.len Total Length
4 32 ip.id Identification
6 48 - Reserved Bit (must be zero)
6 49 ip.flags.df Don't Fragment (DF)
6 50 ip.flags.mf More Fragments (MF)
6 51 ip.frag_offset Fragment Offset
8 64 ip.ttl Time To Live (TTL)
9 72 ip.proto Protocol (Transport Layer)
10 80 ip.checksum Header Checksum
12 96 ip.src Source IP Address
16 128 ip.dst Destination IP Address
20 160 ip.options IP Options (if IHL > 5)
"""
if length is None:
length = len(self)
_vihl = self._read_fileng(1).hex()
_dscp = self._read_binary(1)
_tlen = self._read_unpack(2)
_iden = self._read_unpack(2)
_frag = self._read_binary(2)
_ttol = self._read_unpack(1)
_prot = self._read_protos(1)
_csum = self._read_fileng(2)
_srca = self._read_ipv4_addr()
_dsta = self._read_ipv4_addr()
ipv4 = dict(
version=_vihl[0],
hdr_len=int(_vihl[1], base=16) * 4,
dsfield=dict(
dscp=(
TOS_PRE.get(int(_dscp[:3], base=2)),
TOS_DEL.get(int(_dscp[3], base=2)),
TOS_THR.get(int(_dscp[4], base=2)),
TOS_REL.get(int(_dscp[5], base=2)),
),
ecn=TOS_ECN.get(int(_dscp[-2:], base=2)),
),
len=_tlen,
id=_iden,
flags=dict(
df=True if int(_frag[1]) else False,
mf=True if int(_frag[2]) else False,
),
frag_offset=int(_frag[3:], base=2) * 8,
ttl=_ttol,
proto=_prot,
checksum=_csum,
src=_srca,
dst=_dsta,
)
_optl = ipv4['hdr_len'] - 20
if _optl:
options = self._read_ipv4_options(_optl)
ipv4['opt'] = options[0] # tuple of option acronyms
ipv4.update(options[1]) # merge option info to buffer
# ipv4['opt'] = self._read_fileng(_optl) or None
hdr_len = ipv4['hdr_len']
raw_len = ipv4['len'] - hdr_len
ipv4['packet'] = self._read_packet(header=hdr_len, payload=raw_len)
return self._decode_next_layer(ipv4, _prot, raw_len) | Read Internet Protocol version 4 (IPv4).
Structure of IPv4 header [RFC 791]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version| IHL |Type of Service| Total Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identification |Flags| Fragment Offset |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Time to Live | Protocol | Header Checksum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Destination Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Octets Bits Name Description
0 0 ip.version Version (4)
0 4 ip.hdr_len Internal Header Length (IHL)
1 8 ip.dsfield.dscp Differentiated Services Code Point (DSCP)
1 14 ip.dsfield.ecn Explicit Congestion Notification (ECN)
2 16 ip.len Total Length
4 32 ip.id Identification
6 48 - Reserved Bit (must be zero)
6 49 ip.flags.df Don't Fragment (DF)
6 50 ip.flags.mf More Fragments (MF)
6 51 ip.frag_offset Fragment Offset
8 64 ip.ttl Time To Live (TTL)
9 72 ip.proto Protocol (Transport Layer)
10 80 ip.checksum Header Checksum
12 96 ip.src Source IP Address
16 128 ip.dst Destination IP Address
20 160 ip.options IP Options (if IHL > 5) | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/ipv4.py#L166-L257 |
JarryShaw/PyPCAPKit | src/protocols/internet/ipv4.py | IPv4._read_opt_type | def _read_opt_type(self, kind):
"""Read option type field.
Positional arguments:
* kind -- int, option kind value
Returns:
* dict -- extracted IPv4 option
Structure of option type field [RFC 791]:
Octets Bits Name Descriptions
0 0 ip.opt.type.copy Copied Flag (0/1)
0 1 ip.opt.type.class Option Class (0-3)
0 3 ip.opt.type.number Option Number
"""
bin_ = bin(kind)[2:].zfill(8)
type_ = {
'copy': bool(int(bin_[0], base=2)),
'class': opt_class.get(int(bin_[1:3], base=2)),
'number': int(bin_[3:], base=2),
}
return type_ | python | def _read_opt_type(self, kind):
"""Read option type field.
Positional arguments:
* kind -- int, option kind value
Returns:
* dict -- extracted IPv4 option
Structure of option type field [RFC 791]:
Octets Bits Name Descriptions
0 0 ip.opt.type.copy Copied Flag (0/1)
0 1 ip.opt.type.class Option Class (0-3)
0 3 ip.opt.type.number Option Number
"""
bin_ = bin(kind)[2:].zfill(8)
type_ = {
'copy': bool(int(bin_[0], base=2)),
'class': opt_class.get(int(bin_[1:3], base=2)),
'number': int(bin_[3:], base=2),
}
return type_ | Read option type field.
Positional arguments:
* kind -- int, option kind value
Returns:
* dict -- extracted IPv4 option
Structure of option type field [RFC 791]:
Octets Bits Name Descriptions
0 0 ip.opt.type.copy Copied Flag (0/1)
0 1 ip.opt.type.class Option Class (0-3)
0 3 ip.opt.type.number Option Number | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/ipv4.py#L285-L310 |
JarryShaw/PyPCAPKit | src/protocols/internet/ipv4.py | IPv4._read_ipv4_options | def _read_ipv4_options(self, size=None):
"""Read IPv4 option list.
Positional arguments:
* size -- int, buffer size
Returns:
* tuple -- IPv4 option list
* dict -- extracted IPv4 option
"""
counter = 0 # length of read option list
optkind = list() # option kind list
options = dict() # dict of option data
while counter < size:
# get option kind
kind = self._read_unpack(1)
# fetch corresponding option tuple
opts = IPv4_OPT.get(kind)
if opts is None:
len_ = size - counter
counter = size
options['Unknown'] = self._read_fileng(len_)
break
# extract option
dscp = OPT_TYPE.get(kind)
desc = dscp.name
if opts[0]:
byte = self._read_unpack(1)
if byte: # check option process mode
data = process_opt[opts[2]](self, byte, kind)
else: # permission options (length is 2)
data = dict(
kind=kind, # option kind
type=self._read_opt_type(kind), # option type info
length=2, # option length
flag=True, # permission flag
)
else: # 1-bytes options
byte = 1
data = dict(
kind=kind, # option kind
type=self._read_opt_type(kind), # option type info
length=1, # option length
)
# record option data
counter += byte
if dscp in optkind:
if isinstance(options[desc], tuple):
options[desc] += (Info(data),)
else:
options[desc] = (Info(options[desc]), Info(data))
else:
optkind.append(dscp)
options[desc] = data
# break when eol triggered
if not kind:
break
# get padding
if counter < size:
len_ = size - counter
self._read_binary(len_)
return tuple(optkind), options | python | def _read_ipv4_options(self, size=None):
"""Read IPv4 option list.
Positional arguments:
* size -- int, buffer size
Returns:
* tuple -- IPv4 option list
* dict -- extracted IPv4 option
"""
counter = 0 # length of read option list
optkind = list() # option kind list
options = dict() # dict of option data
while counter < size:
# get option kind
kind = self._read_unpack(1)
# fetch corresponding option tuple
opts = IPv4_OPT.get(kind)
if opts is None:
len_ = size - counter
counter = size
options['Unknown'] = self._read_fileng(len_)
break
# extract option
dscp = OPT_TYPE.get(kind)
desc = dscp.name
if opts[0]:
byte = self._read_unpack(1)
if byte: # check option process mode
data = process_opt[opts[2]](self, byte, kind)
else: # permission options (length is 2)
data = dict(
kind=kind, # option kind
type=self._read_opt_type(kind), # option type info
length=2, # option length
flag=True, # permission flag
)
else: # 1-bytes options
byte = 1
data = dict(
kind=kind, # option kind
type=self._read_opt_type(kind), # option type info
length=1, # option length
)
# record option data
counter += byte
if dscp in optkind:
if isinstance(options[desc], tuple):
options[desc] += (Info(data),)
else:
options[desc] = (Info(options[desc]), Info(data))
else:
optkind.append(dscp)
options[desc] = data
# break when eol triggered
if not kind:
break
# get padding
if counter < size:
len_ = size - counter
self._read_binary(len_)
return tuple(optkind), options | Read IPv4 option list.
Positional arguments:
* size -- int, buffer size
Returns:
* tuple -- IPv4 option list
* dict -- extracted IPv4 option | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/ipv4.py#L312-L382 |
JarryShaw/PyPCAPKit | src/protocols/internet/ipv4.py | IPv4._read_mode_donone | def _read_mode_donone(self, size, kind):
"""Read options request no process.
Positional arguments:
* size - int, length of option
* kind - int, option kind value
Returns:
* dict -- extracted option
Structure of IPv4 options:
Octets Bits Name Description
0 0 ip.opt.kind Kind
0 0 ip.opt.type.copy Copied Flag
0 1 ip.opt.type.class Option Class
0 3 ip.opt.type.number Option Number
1 8 ip.opt.length Length
2 16 ip.opt.data Kind-specific Data
"""
if size < 3:
raise ProtocolError(f'{self.alias}: [Optno {kind}] invalid format')
data = dict(
kind=kind,
type=self._read_opt_type(kind),
length=size,
data=self._read_fileng(size),
)
return data | python | def _read_mode_donone(self, size, kind):
"""Read options request no process.
Positional arguments:
* size - int, length of option
* kind - int, option kind value
Returns:
* dict -- extracted option
Structure of IPv4 options:
Octets Bits Name Description
0 0 ip.opt.kind Kind
0 0 ip.opt.type.copy Copied Flag
0 1 ip.opt.type.class Option Class
0 3 ip.opt.type.number Option Number
1 8 ip.opt.length Length
2 16 ip.opt.data Kind-specific Data
"""
if size < 3:
raise ProtocolError(f'{self.alias}: [Optno {kind}] invalid format')
data = dict(
kind=kind,
type=self._read_opt_type(kind),
length=size,
data=self._read_fileng(size),
)
return data | Read options request no process.
Positional arguments:
* size - int, length of option
* kind - int, option kind value
Returns:
* dict -- extracted option
Structure of IPv4 options:
Octets Bits Name Description
0 0 ip.opt.kind Kind
0 0 ip.opt.type.copy Copied Flag
0 1 ip.opt.type.class Option Class
0 3 ip.opt.type.number Option Number
1 8 ip.opt.length Length
2 16 ip.opt.data Kind-specific Data | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/ipv4.py#L384-L414 |
JarryShaw/PyPCAPKit | src/protocols/internet/ipv4.py | IPv4._read_mode_unpack | def _read_mode_unpack(self, size, kind):
"""Read options request unpack process.
Positional arguments:
* size - int, length of option
* kind - int, option kind value
Returns:
* dict -- extracted option
Structure of IPv4 options:
Octets Bits Name Description
0 0 ip.opt.kind Kind
0 0 ip.opt.type.copy Copied Flag
0 1 ip.opt.type.class Option Class
0 3 ip.opt.type.number Option Number
1 8 ip.opt.length Length
2 16 ip.opt.data Kind-specific Data
"""
if size < 3:
raise ProtocolError(f'{self.alias}: [Optno {kind}] invalid format')
data = dict(
kind=kind,
type=self._read_opt_type(kind),
length=size,
data=self._read_unpack(size),
)
return data | python | def _read_mode_unpack(self, size, kind):
"""Read options request unpack process.
Positional arguments:
* size - int, length of option
* kind - int, option kind value
Returns:
* dict -- extracted option
Structure of IPv4 options:
Octets Bits Name Description
0 0 ip.opt.kind Kind
0 0 ip.opt.type.copy Copied Flag
0 1 ip.opt.type.class Option Class
0 3 ip.opt.type.number Option Number
1 8 ip.opt.length Length
2 16 ip.opt.data Kind-specific Data
"""
if size < 3:
raise ProtocolError(f'{self.alias}: [Optno {kind}] invalid format')
data = dict(
kind=kind,
type=self._read_opt_type(kind),
length=size,
data=self._read_unpack(size),
)
return data | Read options request unpack process.
Positional arguments:
* size - int, length of option
* kind - int, option kind value
Returns:
* dict -- extracted option
Structure of IPv4 options:
Octets Bits Name Description
0 0 ip.opt.kind Kind
0 0 ip.opt.type.copy Copied Flag
0 1 ip.opt.type.class Option Class
0 3 ip.opt.type.number Option Number
1 8 ip.opt.length Length
2 16 ip.opt.data Kind-specific Data | https://github.com/JarryShaw/PyPCAPKit/blob/c7f0da9aebc2cf210bf8f8b912f7d3cbb98ca10e/src/protocols/internet/ipv4.py#L416-L446 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.