Invalid argument with SendMsg() cmsg in golang

32 Views Asked by At

I am new in golang and socket programming. I am trying to send msg with cmsg , but the error keep showing with "Invalid argument" when invoking syscall.Sendmsg(). I am sure that call works well without cmsgBytes.

...
    cmsg := syscall.Cmsghdr{}
    cmsg.Level = syscall.SOL_SOCKET
    cmsg.Type = syscall.SO_TIMESTAMPING
    cmsg.Len = uint64(syscall.CmsgLen(0))
    cmsgBytes := (*[unsafe.Sizeof(cmsg)]byte)(unsafe.Pointer(&cmsg))[:]

    if err := syscall.Sendmsg(fd, pkt, cmsgBytes, dstAddr, 0); err != nil {
        return time.Time{}, err
}

Please tell me some example of sending cmsg data with SO_TIMESTAMPING or anything can help.

0

There are 0 best solutions below