* scmDataToTime parses SocketControlMessage Data field into time.Time. The structure can return up to three timestamps. This is a legacy feature. Only one field is non-zero at any time. Most timestamps are passed in ts[0]. Hardware timestamps are passed in ts[2]. */
(data []byte)
| 54 | // 2 x 64bit ints |
| 55 | size := 16 |
| 56 | // first, try to use hardware timestamps |
| 57 | ts, err = byteToTime(data[size*2 : size*3]) |
| 58 | if err != nil { |
| 59 | return ts, err |
| 60 | } |
| 61 | // if hw timestamps aren't present, use software timestamps |
| 62 | // we can't use ts.IsZero because for some crazy reason timestamp parsed using time.Unix() |
| 63 | // reports IsZero() == false, even if seconds and nanoseconds are zero. |
| 64 | if ts.UnixNano() == 0 { |
| 65 | ts, err = byteToTime(data[0:size]) |
| 66 | if err != nil { |
| 67 | return ts, err |
| 68 | } |
| 69 | if ts.UnixNano() == 0 { |
| 70 | return ts, fmt.Errorf("got zero timestamp") |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | return ts, nil |
| 75 | } |
| 76 | |
| 77 | // scmDataToSeqID parses SocketControlMessage Data field to get the SequenceID |
| 78 | func scmDataToSeqID(data []byte) (seqID uint32, err error) { |
| 79 | se := (*unix.SockExtendedErr)(unsafe.Pointer(&data[0])) |
| 80 | if unix.Errno(se.Errno) != unix.ENOMSG { |
| 81 | return 0, fmt.Errorf("expected ENOMSG but got %w", unix.Errno(se.Errno)) |
searching dependent graphs…