Skip to content

Commit

Permalink
fix for windows/macos
Browse files Browse the repository at this point in the history
  • Loading branch information
jkralik committed Nov 13, 2023
1 parent 164d34e commit 172ca1e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions net/connUDP.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,12 @@ func (c *UDPConn) writeToAddr(iface *net.Interface, src *net.IP, multicastHopLim
return err
}
cm := toControlMessage(p, iface, src)
if !supportsSetPacketControlMessage(c.connection) {

Check failure on line 364 in net/connUDP.go

View workflow job for this annotation

GitHub Actions / test (macOS-latest)

undefined: supportsSetPacketControlMessage
// if remote address is set, we can use it as destination address
// because connection is already connected
// only linux supports overwriting destination address
cm = nil
}
_, err = p.WriteTo(buffer, cm, raddr)
return err
}
Expand Down
5 changes: 5 additions & 0 deletions net/connUDP_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,18 @@ func TestPacketConnIPv4ReadFrom(t *testing.T) {
errC := readUDP4Conn.Close()
require.NoError(t, errC)
}()

require.Nil(t, readUDP4Conn.RemoteAddr())

writeUDP4Conn, err := net.DialUDP("udp4", nil, readUDP4Conn.LocalAddr().(*net.UDPAddr))
require.NoError(t, err)
defer func() {
errC := writeUDP4Conn.Close()
require.NoError(t, errC)
}()

require.NotNil(t, writeUDP4Conn.RemoteAddr())

readUDP6Conn, err := net.ListenUDP("udp6", &net.UDPAddr{Port: 1235})
require.NoError(t, err)
defer func() {
Expand Down
9 changes: 9 additions & 0 deletions net/supportsSetPacketControlMessage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build !linux

package net

import "net"

func supportsSetPacketDestination(c *net.UDPConn) bool {
return c.RemoteAddr() == nil
}
7 changes: 7 additions & 0 deletions net/supportsSetPacketControlMessage_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net

import "net"

func supportsSetPacketControlMessage(*net.UDPConn) bool {
return true
}

0 comments on commit 172ca1e

Please sign in to comment.