socketControlMessageTimestamp is a very optimised version of ParseSocketControlMessage https://github.com/golang/go/blob/2ebe77a2fda1ee9ff6fd9a3e08933ad1ebaea039/src/syscall/sockcmsg_unix.go#L40 which only parses the timestamp message type
(b []byte, boob int)
| 266 | mlen := 0 |
| 267 | for i := 0; i < boob; i += unix.CmsgSpace(mlen - unix.SizeofCmsghdr) { |
| 268 | h := (*unix.Cmsghdr)(unsafe.Pointer(&b[i])) |
| 269 | mlen = int(h.Len) //#nosec G115 |
| 270 | if mlen == 0 { |
| 271 | break |
| 272 | } |
| 273 | // depending on the kernel version, when we ask for SO_TIMESTAMPING_NEW we still might get messages with type SO_TIMESTAMPING |
| 274 | if h.Level == unix.SOL_SOCKET && int(h.Type) == unix.SO_TIMESTAMPING_NEW || int(h.Type) == unix.SO_TIMESTAMPING { |
| 275 | return scmDataToTime(b[i+socketControlMessageHeaderOffset : i+mlen]) |
| 276 | } |
| 277 | } |
| 278 | return time.Time{}, ErrNoTimestamp |
| 279 | } |
| 280 | |
| 281 | // socketControlMessageDrops parses SocketControlMessage for drops count |
| 282 | // drops are provided by SO_RXQ_OVFL control message when enabled |
| 283 | func socketControlMessageDrops(b []byte, boob int) uint32 { |
| 284 | mlen := 0 |
| 285 | var drops uint32 |
searching dependent graphs…