Native Search Active Devices Protocol (CSADP)¶
A module covering layer II networking elements.
Note: If you can’t see any contents below, ReadTheDocs-build fails on this module. Please refer to the documented source code instead.
Usage:
from hiktools import csadp
# Because the following module requires root priviledges it
# has to be imported directly.
from hiktools.csadp import CService
sock = CService.l2socket('wlan0')
counter = 0x115e
# To build an Inquiry packet, we need the following information:
# - our mac, ipv4 and ipv6 address (and the counter of course)
packet = csadp.Inquiry('<MAC>', '<IPv4>', '<IPv6>', counter)
# before we can send the message, a checksum has to be calculated
packet.insert_checksum()
sock.send(bytes(packet))
response = csadp.SADPPacket(sock.recv(1024))
# to view the contents just print the str() version
print(str(response))
- hiktools.csadp.Checksum(buf: uintarray, prefix: int) int¶
The SADP checksum algorithm implemented in python3.
For a more accurate view on the algorithm, see the C++ source code on the hiktools repository on github.
- Parameters:
buf – an unsinged int16 array (can be created via a call to
to_uint16_buf())prefix – the sender’s type specification. As defined in the C++ header file,
0x42specifies a client and0xf6an server.
- hiktools.csadp.inet_stomac(mac: str) bytes¶
Converts the string mac address into a byte buffer.
- hiktools.csadp.inet_mactos(buffer: bytes, index: int, sep: str = ':') str¶
Converts bytes to a MAC address.
- hiktools.csadp.inet_iptos(buffer: bytes, offset: int) str¶
Converts bytes to an IP address.
- hiktools.csadp.inet_stoip(ip: str) bytes¶
Converts the string ip address into a byte buffer.
- hiktools.csadp.inet6_stoip(ip6: str) bytes¶
Converts the string ip address into a byte buffer.
- hiktools.csadp.inet6_iptos(buffer: bytes, offset: int) str¶
Converts bytes to an IP address.
- hiktools.csadp.payload(ptype: int)¶
Simple class descriptor to register payload types
Use this descriptor to define payload classes that are used within the parsing process of a
SADPPacket. Note that this method will raise aNameErrorif the payload type has already been assigned to another class.Example for registering a payload class for the UpdateIP packet type.
>>> @payload(PACKET_TYPE['UpdateIP']) >>> class MySADPPayload(SADPPayload): ... pass
- Parameters:
ptype – the packet type the payload class should be mapped to
- class hiktools.csadp.EthernetHeader(buf: bytes | None = None)¶
Small wrapper for raw ethernet message headers.
The basic structure of this header is defined as follows:
>>> +-------------------------------------------------+ >>> | EthernetHeader | >>> +---------------+--------------+------------------+ >>> | dest: byte[6] | src: byte[6] | eth_type: uint16 | >>> +---------------+--------------+------------------+
- Parameters:
dest (str) – The destination MAC address of this packet. Usually this field points to the multicast MAC address (
FF:FF:FF:FF:FF:FF).src (str) – the source MAC address for this packet
eth_type (uint16 (int)) – The specified ethernet type for this packet. This value can be used for validation, because it has to be
0x8033.
- class hiktools.csadp.SADPHeader(buf: bytes | None = None)¶
A simple class wrapper to store header variables of SADPPackets.
- class hiktools.csadp.SADPPayload(buf: bytes | None = None)¶
The base class for all payload types.