diff --git a/internal/utils/ip.go b/internal/utils/ip.go deleted file mode 100644 index 7ac7ffec..00000000 --- a/internal/utils/ip.go +++ /dev/null @@ -1,10 +0,0 @@ -package utils - -import "net" - -func IsIPv4(ip net.IP) bool { - // If ip is not an IPv4 address, To4 returns nil. - // Note that there might be some corner cases, where this is not correct. - // See https://stackoverflow.com/questions/22751035/golang-distinguish-ipv4-ipv6. - return ip.To4() != nil -} diff --git a/internal/utils/ip_test.go b/internal/utils/ip_test.go deleted file mode 100644 index fdeec2e2..00000000 --- a/internal/utils/ip_test.go +++ /dev/null @@ -1,17 +0,0 @@ -package utils - -import ( - "net" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -var _ = Describe("IP", func() { - It("tells IPv4 and IPv6 addresses apart", func() { - Expect(IsIPv4(net.IPv4(127, 0, 0, 1))).To(BeTrue()) - Expect(IsIPv4(net.IPv4zero)).To(BeTrue()) - Expect(IsIPv4(net.IPv6zero)).To(BeFalse()) - Expect(IsIPv4(net.IPv6loopback)).To(BeFalse()) - }) -}) diff --git a/qlog/event.go b/qlog/event.go index 7602b55c..55fc3d5e 100644 --- a/qlog/event.go +++ b/qlog/event.go @@ -9,7 +9,6 @@ import ( "github.com/quic-go/quic-go" "github.com/quic-go/quic-go/internal/protocol" - "github.com/quic-go/quic-go/internal/utils" "github.com/quic-go/quic-go/logging" "github.com/francoispqt/gojay" @@ -72,7 +71,7 @@ func (e eventConnectionStarted) Name() string { return "connection_started func (e eventConnectionStarted) IsNil() bool { return false } func (e eventConnectionStarted) MarshalJSONObject(enc *gojay.Encoder) { - if utils.IsIPv4(e.SrcAddr.IP) { + if e.SrcAddr.IP.To4() != nil { enc.StringKey("ip_version", "ipv4") } else { enc.StringKey("ip_version", "ipv6") diff --git a/sys_conn_oob_test.go b/sys_conn_oob_test.go index a24480ab..7fe74eff 100644 --- a/sys_conn_oob_test.go +++ b/sys_conn_oob_test.go @@ -11,7 +11,6 @@ import ( "golang.org/x/sys/unix" "github.com/quic-go/quic-go/internal/protocol" - "github.com/quic-go/quic-go/internal/utils" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -28,6 +27,8 @@ func (c *oobRecordingConn) WriteMsgUDP(b, oob []byte, addr *net.UDPAddr) (n, oob return c.UDPConn.WriteMsgUDP(b, oob, addr) } +func isIPv4(ip net.IP) bool { return ip.To4() != nil } + var _ = Describe("OOB Conn Test", func() { runServer := func(network, address string) (*net.UDPConn, <-chan receivedPacket) { addr, err := net.ResolveUDPAddr(network, address) @@ -123,7 +124,7 @@ var _ = Describe("OOB Conn Test", func() { var p receivedPacket Eventually(packetChan).Should(Receive(&p)) - Expect(utils.IsIPv4(p.remoteAddr.(*net.UDPAddr).IP)).To(BeTrue()) + Expect(isIPv4(p.remoteAddr.(*net.UDPAddr).IP)).To(BeTrue()) Expect(p.ecn).To(Equal(protocol.ECNCE)) // IPv6 @@ -136,7 +137,7 @@ var _ = Describe("OOB Conn Test", func() { ) Eventually(packetChan).Should(Receive(&p)) - Expect(utils.IsIPv4(p.remoteAddr.(*net.UDPAddr).IP)).To(BeFalse()) + Expect(isIPv4(p.remoteAddr.(*net.UDPAddr).IP)).To(BeFalse()) Expect(p.ecn).To(Equal(protocol.ECT1)) }) @@ -233,7 +234,7 @@ var _ = Describe("OOB Conn Test", func() { var p receivedPacket Eventually(packetChan).Should(Receive(&p)) - Expect(utils.IsIPv4(p.remoteAddr.(*net.UDPAddr).IP)).To(BeTrue()) + Expect(isIPv4(p.remoteAddr.(*net.UDPAddr).IP)).To(BeTrue()) Expect(p.info).To(Not(BeNil())) Expect(p.info.addr.Is4()).To(BeTrue()) ip := p.info.addr.As4() @@ -244,7 +245,7 @@ var _ = Describe("OOB Conn Test", func() { sendPacket("udp6", &net.UDPAddr{IP: net.IPv6loopback, Port: port}) Eventually(packetChan).Should(Receive(&p)) - Expect(utils.IsIPv4(p.remoteAddr.(*net.UDPAddr).IP)).To(BeFalse()) + Expect(isIPv4(p.remoteAddr.(*net.UDPAddr).IP)).To(BeFalse()) Expect(p.info).To(Not(BeNil())) Expect(net.IP(p.info.addr.AsSlice())).To(Equal(ip6)) })