I’m receiving a struct over a network from a C server to my Python client. The protocol is UDP. I have no control over the server and it’s protocols/data formats. It consists of this struct (yes, an IPv4 + port):
struct ip_s {
uint8_t i1;
uint8_t i2;
uint8_t i3;
uint8_t i4;
uint16_t port; // big endian
};
Apart from the port which is converted to big-endian the data is sent “as-is”, casted to a (char*).
How can I receive this struct to a format that is processable by Python?
Misc info:
- Python 2.7 or 3.x
- Cross-platform
- Preferably solution using only built-in modules
Look into struct.unpack
It will probably look something like this: