On Jan 10, 2013, at 5:38 AM, Julius Bachnick wrote:
> I was wondering whether it is somehow possible to get the packet data +
> header of a packe I handle via _handle_PacketIn as array of unsigned chars. I
> looked into the code of packet base but that did not help me much yet.
The raw data is available as a bytes object (in Python 2.x, that's the same as
a str -- an 8 bit immutable sequence of characters) in the event's .data
attribute. You can use ord() to convert individual characters to their numeric
value.
Since what you really want are those numeric values ("unsigned char" doesn't
mean much in Python), you might just want to convert from a bytes object to a
bytearray object: b = bytearray(event.data). Now b[1] is the same thing as if
you'd done ord(event.data[1]).
> Having it as array would facilitate examine certain fields within that
> packet, which is basically what I want to do. Unfortunately, since it is
> STP/BPDU I cannot use one of the Parsers provided by POX so I though about
> just forwarding the entire packet to my Handler when I faced the issue I
> mentioned above.
As you say, POX's packet library (pox.lib.packet) doesn't handle STP. Instead
of going the "raw bytes" route above, you might try doing what the packet
library largely does: use Python's struct module to parse values out of the raw
bytes object.
For that matter, you might consider extending the packet library to support STP
and then issue a pull request! :) If you do go this route, you might dig
through the repository's history... the packet library used to support LLC; I
dropped it at some point because it wasn't getting used and it was out of date.
Even if you don't go as far as extending the packet library, if you get some
reusable BPDU parsing code working, please consider posting it.
Good luck.
-- Murphy