func TimeFromDevice(device string) (time.Time, error) {
	f, err := os.Open(device)
	if err != nil {
		return time.Time{}, err
	}
	defer f.Close()
	var ts unix.Timespec
	if err := unix.ClockGettime(fdToClockID(f.Fd()), &ts); err != nil {
		return time.Time{}, fmt.Errorf("failed clock_gettime: %w", err)
	}
	return time.Unix(ts.Unix()), nil
}
TimeFromDevice returns time we got from PTP device
package phc
import (
	"fmt"
	"os"
	"time"
	"unsafe"
	"golang.org/x/sys/unix"
)
type PTPClockTime struct {
	Sec      int64   
	NSec     uint32  
	Reserved uint32
}
func (t PTPClockTime) Time() time.Time {
	return time.Unix(t.Sec, int64(t.NSec))
}
func fdToClockID(fd uintptr) int32 {
	return int32((int(^fd) << 3) | 3)
}
type TimeMethod string
const (
	MethodSyscallClockGettime    TimeMethod = "syscall_clock_gettime"
	MethodIoctlSysOffsetExtended TimeMethod = "ioctl_PTP_SYS_OFFSET_EXTENDED"
)
var SupportedMethods = []TimeMethod{MethodSyscallClockGettime, MethodIoctlSysOffsetExtended}
func Time(iface string, method TimeMethod) (time.Time, error) {
	info, err := IfaceInfo(iface)
	if err != nil {
		return time.Time{}, fmt.Errorf("getting interface info: %w", err)
	}
	if info.PHCIndex < 0 {
		return time.Time{}, fmt.Errorf("%s doesn't support PHC", iface)
	}
	device := fmt.Sprintf("/dev/ptp%d", info.PHCIndex)
	switch method {
	case MethodSyscallClockGettime:
		return TimeFromDevice(device)
	case MethodIoctlSysOffsetExtended:
		extended, err := ReadPTPSysOffsetExtended(device, 1)
		if err != nil {
			return time.Time{}, err
		}
		latest := extended.TS[extended.NSamples-1]
		return latest[1].Time(), nil
	}
	return time.Time{}, fmt.Errorf("unknown method to get PHC time %q", method)
}