EnableHWTimestamps enables HW timestamps (TX and RX) on the socket
(connFd int, iface *net.Interface)
| 173 | rxFilter, err := ioctlHWTimestampCaps(connFd, iface.Name) |
| 174 | if err != nil { |
| 175 | return err |
| 176 | } |
| 177 | if err := ioctlTimestamp(connFd, iface.Name, rxFilter); err != nil { |
| 178 | return err |
| 179 | } |
| 180 | |
| 181 | // Enable hardware timestamp capabilities on socket |
| 182 | flags := unix.SOF_TIMESTAMPING_TX_HARDWARE | |
| 183 | unix.SOF_TIMESTAMPING_RX_HARDWARE | |
| 184 | unix.SOF_TIMESTAMPING_RAW_HARDWARE | |
| 185 | // Makes the kernel return the timestamp as a cmsg with a unique ID in second cmsg to identify the SYNC packet that the timestamp is associated with |
| 186 | unix.SOF_TIMESTAMPING_OPT_ID | |
| 187 | // Makes the kernel return the timestamp as a cmsg alongside an empty packet, as opposed to alongside the original packet |
| 188 | unix.SOF_TIMESTAMPING_OPT_TSONLY |
| 189 | // Allow reading of HW timestamps via socket |
| 190 | if err := unix.SetsockoptInt(connFd, unix.SOL_SOCKET, timestamping, flags); err != nil { |
| 191 | return err |
| 192 | } |
| 193 | |
| 194 | // Bind socket to the interface |
| 195 | _ = unix.SetsockoptInt(connFd, unix.SOL_SOCKET, unix.SO_BINDTODEVICE, iface.Index) |
| 196 | |
| 197 | return unix.SetsockoptInt(connFd, unix.SOL_SOCKET, unix.SO_SELECT_ERR_QUEUE, 1) |
| 198 | } |
| 199 | |
| 200 | // EnableHWTimestampsRx enables HW RX timestamps on the socket |
| 201 | func EnableHWTimestampsRx(connFd int, iface *net.Interface) error { |
| 202 | rxFilter, err := ioctlHWTimestampCaps(connFd, iface.Name) |
| 203 | if err != nil { |
| 204 | return err |
no test coverage detected
searching dependent graphs…