From 822f5a6d70c22df93ed1680fbe14ef3733647e89 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Mon, 29 Mar 2021 13:11:11 -0700 Subject: 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 --- conn/bind_std.go | 27 +++++++++++++-------------- 1 file 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 } -- cgit v1.2.3