I am writing a program that analyzes DHCP packets and came across option 43 (Vendor Specification). This is more of a programming issue and less technically related to network and DHCP, so I marked it as just python.
According to RFC 2132 (p. 19), the structure of option 43 is as follows:
Code Len Data item Code Len Data item Code
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| T1 | n | d1 | d2 | ... | T2 | n | D1 | D2 | ... | ... |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
When moving to a python byte object, it should look something like this:
[T1, n, d1, d2, ..., T2, n, D1, D2, ...]
Where n is the length of the data element (Dn).
Ideally, I want to iterate over this byte object and save the code for each data item as a key and map it to the corresponding data item value. IE:
{T1: [d1, d2, d3], T2: [D1, D2, D3]}
For instance:
[0, 1, 2, 1, 2, 5, 6, 3, 4, 9, 10, 11, 12]
Should translate to this:
{0: [2], 1: [5,6], 3: [9, 10, 11, 12]}
Is there a proper way to do this in python?
EDIT: Yes, yes. Codes (Tn) are unique.