ptp.c
void ptp_extract_timestamps(struct TimestampI *ts, void *pPayload, uint8_t n)
{
    uint8_t *p = ((uint8_t*) pPayload) + PTP_HEADER_LENGTH; // pointer at the beginning of first timestamp

    // read n times
    uint8_t i;
    for (i = 0; i < n; i++)
    {
        // seconds
        ts->sec = 0;
        memcpy(&ts->sec, p, 6); // 48-bit
        p += 6;

        // nanoseconds
        memcpy(&ts->nanosec, p, 4);
        p += 4;

        // network->host
        ts->sec = ntohll(ts->sec << 16);
        ts->nanosec = ntohl(ts->nanosec);

        // step to next timestamp
        ts++;
    }
}
// extract n timestamps from a message
extract n timestamps from a message
extract n timestamps from a message
void ptp_extract_timestamps(struct TimestampI *ts, void *pPayload, uint8_t n)
{
    uint8_t *p = ((uint8_t*) pPayload) + PTP_HEADER_LENGTH; 
    uint8_t i;
    for (i = 0; i < n; i++)
    {
        ts->sec = 0;
        memcpy(&ts->sec, p, 6); 
        p += 6;
        memcpy(&ts->nanosec, p, 4);
        p += 4;
        ts->sec = ntohll(ts->sec << 16);
        ts->nanosec = ntohl(ts->nanosec);
        ts++;
    }
}
void ptp_extract_timestamps ( struct TimestampI * ts , void * pPayload , uint8_t n ) { uint8_t * p = ( ( uint8_t * ) pPayload ) + PTP_HEADER_LENGTH ; uint8_t i ; for ( i = 0 ; i < n ; i ++ ) { ts -> sec = 0 ; memcpy ( & ts -> sec , p , 6 ) ; p += 6 ; memcpy ( & ts -> nanosec , p , 4 ) ; p += 4 ; ts -> sec = ntohll ( ts -> sec << 16 ) ; ts -> nanosec = ntohl ( ts -> nanosec ) ; ts ++ ; } }
extract n timestamps from a message
extract n timestamps from a message
// pointer at the beginning of first timestamp // read n times // seconds // 48-bit // nanoseconds // network->host // step to next timestamp