I am writing a PTP client for an embedded system (little endian). PTP is a network protocol for time synchronization which is in network order (big endian). The PTP header and other datatypes are not generally word aligned (some fields are 4 bits long, others are 10 bytes). Is there some clever way to bring the structures into little endian despite the variable alignment.
An example of the PTP header is below:
typedef struct
{
uint8_t message_type : 4;
uint8_t transport_specific : 4;
uint8_t version_ptp : 4;
uint8_t reserved_0 : 4;
uint16_t message_length;
uint8_t domain_number;
uint8_t reserved_1;
uint16_t flags;
uint64_t correction_field;
uint32_t reserved_2;
uint8_t source_port_identiy[10];
uint16_t sequence_id;
uint8_t control_field;
uint8_t log_message_interval;
} __attribute__((packed)) PtpHeader_t;