ptp.c
void ptp_extract_header(struct PTPHeader *pHeader, void *pPayload)
{
    // cast header to byte accessible form
    uint8_t *p = (uint8_t*) pPayload;

    uint16_t flags;

    // copy header fields
    memcpy(&pHeader->messageID, p + 0, 1);
    memcpy(&pHeader->versionPTP, p + 1, 1);
    memcpy(&pHeader->messageLength, p + 2, 2);
    memcpy(&pHeader->subdomainNumber, p + 4, 1);
    memcpy(&flags, p + 6, 2);
    memcpy(&pHeader->correction_ns, p + 8, 8);
    memcpy(&pHeader->clockIdentity, p + 20, 8);
    memcpy(&pHeader->sourcePortID, p + 28, 2);
    memcpy(&pHeader->sequenceID, p + 30, 2);
    memcpy(&pHeader->control, p + 32, 1);
    memcpy(&pHeader->logMessagePeriod, p + 33, 1);

    pHeader->transportSpecific = 0xf0 & pHeader->messageID;
    pHeader->messageID &= 0x0f;

    // read flags
    ptp_load_flags(&pHeader->flags, ntohs(flags));

    // read correction field
    pHeader->correction_subns = ntohll(pHeader->correction_ns) & 0xffff;
    pHeader->correction_ns = ntohll(pHeader->correction_ns) >> 16;

    pHeader->messageLength = ntohs(pHeader->messageLength);
    pHeader->sourcePortID = ntohs(pHeader->sourcePortID);
    pHeader->sequenceID = ntohs(pHeader->sequenceID);
}
// extract fields from a PTP header
extract fields from a PTP header
extract fields from a PTP header
void ptp_extract_header(struct PTPHeader *pHeader, void *pPayload)
{
    uint8_t *p = (uint8_t*) pPayload;
    uint16_t flags;
    memcpy(&pHeader->messageID, p + 0, 1);
    memcpy(&pHeader->versionPTP, p + 1, 1);
    memcpy(&pHeader->messageLength, p + 2, 2);
    memcpy(&pHeader->subdomainNumber, p + 4, 1);
    memcpy(&flags, p + 6, 2);
    memcpy(&pHeader->correction_ns, p + 8, 8);
    memcpy(&pHeader->clockIdentity, p + 20, 8);
    memcpy(&pHeader->sourcePortID, p + 28, 2);
    memcpy(&pHeader->sequenceID, p + 30, 2);
    memcpy(&pHeader->control, p + 32, 1);
    memcpy(&pHeader->logMessagePeriod, p + 33, 1);
    pHeader->transportSpecific = 0xf0 & pHeader->messageID;
    pHeader->messageID &= 0x0f;
    ptp_load_flags(&pHeader->flags, ntohs(flags));
    pHeader->correction_subns = ntohll(pHeader->correction_ns) & 0xffff;
    pHeader->correction_ns = ntohll(pHeader->correction_ns) >> 16;
    pHeader->messageLength = ntohs(pHeader->messageLength);
    pHeader->sourcePortID = ntohs(pHeader->sourcePortID);
    pHeader->sequenceID = ntohs(pHeader->sequenceID);
}
void ptp_extract_header ( struct PTPHeader * pHeader , void * pPayload ) { uint8_t * p = ( uint8_t * ) pPayload ; uint16_t flags ; memcpy ( & pHeader -> messageID , p + 0 , 1 ) ; memcpy ( & pHeader -> versionPTP , p + 1 , 1 ) ; memcpy ( & pHeader -> messageLength , p + 2 , 2 ) ; memcpy ( & pHeader -> subdomainNumber , p + 4 , 1 ) ; memcpy ( & flags , p + 6 , 2 ) ; memcpy ( & pHeader -> correction_ns , p + 8 , 8 ) ; memcpy ( & pHeader -> clockIdentity , p + 20 , 8 ) ; memcpy ( & pHeader -> sourcePortID , p + 28 , 2 ) ; memcpy ( & pHeader -> sequenceID , p + 30 , 2 ) ; memcpy ( & pHeader -> control , p + 32 , 1 ) ; memcpy ( & pHeader -> logMessagePeriod , p + 33 , 1 ) ; pHeader -> transportSpecific = 0xf0 & pHeader -> messageID ; pHeader -> messageID &= 0x0f ; ptp_load_flags ( & pHeader -> flags , ntohs ( flags ) ) ; pHeader -> correction_subns = ntohll ( pHeader -> correction_ns ) & 0xffff ; pHeader -> correction_ns = ntohll ( pHeader -> correction_ns ) >> 16 ; pHeader -> messageLength = ntohs ( pHeader -> messageLength ) ; pHeader -> sourcePortID = ntohs ( pHeader -> sourcePortID ) ; pHeader -> sequenceID = ntohs ( pHeader -> sequenceID ) ; }
extract fields from a PTP header
extract fields from a PTP header
// cast header to byte accessible form // copy header fields // read flags // read correction field