ptp.c
void ptp_construct_binary_header(void *pData, struct PTPHeader *pHeader)
{
    uint8_t *p = (uint8_t*) pData;
    uint8_t firstByte;

    // host->network
    uint16_t messageLength = htons(pHeader->messageLength);
    uint16_t sourcePortID = htons(pHeader->sourcePortID);
    uint16_t sequenceID = htons(pHeader->sequenceID);

    // fill in flags FIXME
    uint16_t flags = 0; // TODO: convert from header fields

    // fill in correction value
    uint64_t correction = htonll((pHeader->correction_ns << 16) | (pHeader->correction_subns)); // TODO: ...

    // copy fields
    firstByte = (pHeader->transportSpecific << 4) | (pHeader->messageID & 0x0f);
    memcpy(p, &firstByte, 1);
    memcpy(p + 1, &pHeader->versionPTP, 1);
    memcpy(p + 2, &messageLength, 2);
    memcpy(p + 4, &pHeader->subdomainNumber, 1);
    memcpy(p + 6, &flags, 2);
    memcpy(p + 8, &correction, 8);
    memcpy(p + 20, &pHeader->clockIdentity, 8);
    memcpy(p + 28, &sourcePortID, 2);
    memcpy(p + 30, &sequenceID, 2);
    memcpy(p + 32, &pHeader->control, 1);
    memcpy(p + 33, &pHeader->logMessagePeriod, 1);
}
// construct binary header from header structure
construct binary header from header structure
construct binary header from header structure
void ptp_construct_binary_header(void *pData, struct PTPHeader *pHeader)
{
    uint8_t *p = (uint8_t*) pData;
    uint8_t firstByte;
    uint16_t messageLength = htons(pHeader->messageLength);
    uint16_t sourcePortID = htons(pHeader->sourcePortID);
    uint16_t sequenceID = htons(pHeader->sequenceID);
    uint16_t flags = 0; 
    uint64_t correction = htonll((pHeader->correction_ns << 16) | (pHeader->correction_subns)); 
    firstByte = (pHeader->transportSpecific << 4) | (pHeader->messageID & 0x0f);
    memcpy(p, &firstByte, 1);
    memcpy(p + 1, &pHeader->versionPTP, 1);
    memcpy(p + 2, &messageLength, 2);
    memcpy(p + 4, &pHeader->subdomainNumber, 1);
    memcpy(p + 6, &flags, 2);
    memcpy(p + 8, &correction, 8);
    memcpy(p + 20, &pHeader->clockIdentity, 8);
    memcpy(p + 28, &sourcePortID, 2);
    memcpy(p + 30, &sequenceID, 2);
    memcpy(p + 32, &pHeader->control, 1);
    memcpy(p + 33, &pHeader->logMessagePeriod, 1);
}
void ptp_construct_binary_header ( void * pData , struct PTPHeader * pHeader ) { uint8_t * p = ( uint8_t * ) pData ; uint8_t firstByte ; uint16_t messageLength = htons ( pHeader -> messageLength ) ; uint16_t sourcePortID = htons ( pHeader -> sourcePortID ) ; uint16_t sequenceID = htons ( pHeader -> sequenceID ) ; uint16_t flags = 0 ; uint64_t correction = htonll ( ( pHeader -> correction_ns << 16 ) | ( pHeader -> correction_subns ) ) ; firstByte = ( pHeader -> transportSpecific << 4 ) | ( pHeader -> messageID & 0x0f ) ; memcpy ( p , & firstByte , 1 ) ; memcpy ( p + 1 , & pHeader -> versionPTP , 1 ) ; memcpy ( p + 2 , & messageLength , 2 ) ; memcpy ( p + 4 , & pHeader -> subdomainNumber , 1 ) ; memcpy ( p + 6 , & flags , 2 ) ; memcpy ( p + 8 , & correction , 8 ) ; memcpy ( p + 20 , & pHeader -> clockIdentity , 8 ) ; memcpy ( p + 28 , & sourcePortID , 2 ) ; memcpy ( p + 30 , & sequenceID , 2 ) ; memcpy ( p + 32 , & pHeader -> control , 1 ) ; memcpy ( p + 33 , & pHeader -> logMessagePeriod , 1 ) ; }
construct binary header from header structure
construct binary header from header structure
// host->network // fill in flags FIXME // TODO: convert from header fields // fill in correction value // TODO: ... // copy fields