diff options
author | Josh Bleecher Snyder <josharian@gmail.com> | 2021-03-29 13:11:11 -0700 |
---|---|---|
committer | Josh Bleecher Snyder <josharian@gmail.com> | 2021-03-30 12:09:32 -0700 |
commit | 822f5a6d70c22df93ed1680fbe14ef3733647e89 (patch) | |
tree | b2f17dfdf840198006730528a220e2cf1c7cd2a1 | |
parent | 02e419ed8af63294fb0d9015d5c77b78fe92709e (diff) |
conn: unify code in StdNetBind.Send
The sending code is identical for ipv4 and ipv6;
select the conn, then use it.
Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
-rw-r--r-- | conn/bind_std.go | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/conn/bind_std.go b/conn/bind_std.go index 28d1464..73946b4 100644 --- a/conn/bind_std.go +++ b/conn/bind_std.go @@ -161,22 +161,21 @@ func (bind *StdNetBind) Send(buff []byte, endpoint Endpoint) error { if !ok { return ErrWrongEndpointType } + var conn *net.UDPConn + var blackhole bool if nend.IP.To4() != nil { - if bind.ipv4 == nil { - return syscall.EAFNOSUPPORT - } - if bind.blackhole4 { - return nil - } - _, err = bind.ipv4.WriteToUDP(buff, (*net.UDPAddr)(nend)) + blackhole = bind.blackhole4 + conn = bind.ipv4 } else { - if bind.ipv6 == nil { - return syscall.EAFNOSUPPORT - } - if bind.blackhole6 { - return nil - } - _, err = bind.ipv6.WriteToUDP(buff, (*net.UDPAddr)(nend)) + blackhole = bind.blackhole6 + conn = bind.ipv6 } + if blackhole { + return nil + } + if conn == nil { + return syscall.EAFNOSUPPORT + } + _, err = conn.WriteToUDP(buff, (*net.UDPAddr)(nend)) return err } |