Skip to content

Commit

Permalink
BGP: Fix IPv4 listen addr configuration
Browse files Browse the repository at this point in the history
  Closes #450

Signed-off-by: Maximilian Wilhelm <[email protected]>
  • Loading branch information
Maximilian Wilhelm committed Oct 11, 2023
1 parent 0e48eb2 commit 4ba4f23
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion net/tcp/tcpsock_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ func ipv6AddrToArray(x net.IP) [16]byte {

func ipv4AddrToArray(x net.IP) [4]byte {
return [4]byte{
x[0], x[1], x[2], x[3],
x[12], x[13], x[14], x[15],
}
}
35 changes: 35 additions & 0 deletions net/tcp/tcpsock_posix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package tcp

import (
"net"
"testing"

"github.com/stretchr/testify/assert"
)

func TestIpv4AddrToArray(t *testing.T) {
tests := []struct {
name string
addr string
expected [4]byte
}{
{
name: "IPv4 / 0.0.0.0",
addr: "0.0.0.0:179",
expected: [4]byte{0, 0, 0, 0},
},
{
name: "IPv4 / 192.0.2.42",
addr: "192.0.2.42:179",
expected: [4]byte{192, 0, 2, 42},
},
}

for _, test := range tests {
tcpaddr, err := net.ResolveTCPAddr("tcp", test.addr)
if err != nil {
t.Fatalf("Failed to resolve TCPAddr: %v", err)
}
assert.Equal(t, test.expected, ipv4AddrToArray(tcpaddr.IP), test.name)
}
}

0 comments on commit 4ba4f23

Please sign in to comment.