(t *testing.T)
| 234 | require.Equal(t, fmt.Errorf("unrecognized timestamp type: Unsupported"), err) |
| 235 | } |
| 236 | |
| 237 | func pktInfo6Cmsg(addr net.IP) []byte { |
| 238 | b := make([]byte, unix.CmsgSpace(unix.SizeofInet6Pktinfo)) |
| 239 | h := (*unix.Cmsghdr)(unsafe.Pointer(&b[0])) |
| 240 | h.Level = unix.IPPROTO_IPV6 |
| 241 | h.Type = unix.IPV6_PKTINFO |
| 242 | h.SetLen(unix.CmsgLen(unix.SizeofInet6Pktinfo)) |
| 243 | pktInfo := (*unix.Inet6Pktinfo)(unsafe.Pointer(&b[socketControlMessageHeaderOffset])) |
| 244 | copy(pktInfo.Addr[:], addr.To16()) |
| 245 | return b |
| 246 | } |
| 247 | |
| 248 | func pktInfo4Cmsg(addr net.IP) []byte { |
| 249 | b := make([]byte, unix.CmsgSpace(unix.SizeofInet4Pktinfo)) |
| 250 | h := (*unix.Cmsghdr)(unsafe.Pointer(&b[0])) |
| 251 | h.Level = unix.IPPROTO_IP |
| 252 | h.Type = unix.IP_PKTINFO |
| 253 | h.SetLen(unix.CmsgLen(unix.SizeofInet4Pktinfo)) |
| 254 | pktInfo := (*unix.Inet4Pktinfo)(unsafe.Pointer(&b[socketControlMessageHeaderOffset])) |
| 255 | copy(pktInfo.Addr[:], addr.To4()) |
| 256 | return b |
| 257 | } |
| 258 | |
| 259 | func TestSocketControlMessageDstAddr(t *testing.T) { |
| 260 | t.Run("IPv6 multicast", func(t *testing.T) { |
| 261 | addr := net.ParseIP("ff0e::181") |
| 262 | b := pktInfo6Cmsg(addr) |
| 263 | dst, err := socketControlMessageDstAddr(b, len(b)) |
| 264 | require.NoError(t, err) |
| 265 | require.True(t, dst.Equal(addr)) |
| 266 | require.True(t, dst.IsMulticast()) |
| 267 | }) |
| 268 | |
| 269 | t.Run("IPv6 unicast", func(t *testing.T) { |
| 270 | addr := net.ParseIP("2401:db00::1") |
| 271 | b := pktInfo6Cmsg(addr) |
| 272 | dst, err := socketControlMessageDstAddr(b, len(b)) |
| 273 | require.NoError(t, err) |
| 274 | require.True(t, dst.Equal(addr)) |
| 275 | require.False(t, dst.IsMulticast()) |
| 276 | }) |
| 277 |
nothing calls this directly
no test coverage detected
searching dependent graphs…