udp_no_control.go raw
1 //go:build windows || darwin
2 // +build windows darwin
3
4 // TODO(tmthrgd): Remove this Windows-specific code if go.dev/issue/7175 and
5 // go.dev/issue/7174 are ever fixed.
6
7 // NOTICE(stek29): darwin supports PKTINFO in sendmsg, but it unbinds sockets, see https://github.com/miekg/dns/issues/724
8
9 package dns
10
11 import "net"
12
13 // SessionUDP holds the remote address
14 type SessionUDP struct {
15 raddr *net.UDPAddr
16 }
17
18 // RemoteAddr returns the remote network address.
19 func (s *SessionUDP) RemoteAddr() net.Addr { return s.raddr }
20
21 // ReadFromSessionUDP acts just like net.UDPConn.ReadFrom(), but returns a session object instead of a
22 // net.UDPAddr.
23 func ReadFromSessionUDP(conn *net.UDPConn, b []byte) (int, *SessionUDP, error) {
24 n, raddr, err := conn.ReadFrom(b)
25 if err != nil {
26 return n, nil, err
27 }
28 return n, &SessionUDP{raddr.(*net.UDPAddr)}, err
29 }
30
31 // WriteToSessionUDP acts just like net.UDPConn.WriteTo(), but uses a *SessionUDP instead of a net.Addr.
32 func WriteToSessionUDP(conn *net.UDPConn, b []byte, session *SessionUDP) (int, error) {
33 return conn.WriteTo(b, session.raddr)
34 }
35
36 func setUDPSocketOptions(*net.UDPConn) error { return nil }
37 func parseDstFromOOB([]byte, net.IP) net.IP { return nil }
38