From 877239a18a3aa27fe2c871e0dbf77dbc8dc59e20 Mon Sep 17 00:00:00 2001 From: Jeremiah Millay Date: Fri, 19 May 2023 10:43:31 -0400 Subject: [PATCH] create error type for unsupported SO_MARK socket option Signed-off-by: Jeremiah Millay --- ping.go | 4 +++- utils_other.go | 10 +++------- utils_windows.go | 8 +++----- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/ping.go b/ping.go index f39fdc5..ae326b9 100644 --- a/ping.go +++ b/ping.go @@ -83,6 +83,8 @@ const ( var ( ipv4Proto = map[string]string{"icmp": "ip4:icmp", "udp": "udp4"} ipv6Proto = map[string]string{"icmp": "ip6:ipv6-icmp", "udp": "udp6"} + + ErrMarkNotSupported = errors.New("setting SO_MARK socket option is not supported on this platform") ) // New returns a new Pinger struct pointer. @@ -191,7 +193,7 @@ type Pinger struct { ipaddr *net.IPAddr addr string - // Mark is a mark (fwmark) set on outgoing icmp packets + // mark is a SO_MARK (fwmark) set on outgoing icmp packets mark uint // trackerUUIDs is the list of UUIDs being used for sending packets. diff --git a/utils_other.go b/utils_other.go index 9b12d9d..80a0a90 100644 --- a/utils_other.go +++ b/utils_other.go @@ -3,10 +3,6 @@ package ping -import ( - "errors" -) - // Returns the length of an ICMP message. func (p *Pinger) getMessageLength() int { return p.Size + 8 @@ -20,17 +16,17 @@ func (p *Pinger) matchID(ID int) bool { // SetMark sets the SO_MARK socket option on outgoing ICMP packets. // Setting this option requires CAP_NET_ADMIN. func (c *icmpConn) SetMark(mark uint) error { - return errors.New("setting SO_MARK socket option is not supported on this platform") + return ErrMarkNotSupported } // SetMark sets the SO_MARK socket option on outgoing ICMP packets. // Setting this option requires CAP_NET_ADMIN. func (c *icmpv4Conn) SetMark(mark uint) error { - return errors.New("setting SO_MARK socket option is not supported on this platform") + return ErrMarkNotSupported } // SetMark sets the SO_MARK socket option on outgoing ICMP packets. // Setting this option requires CAP_NET_ADMIN. func (c *icmpV6Conn) SetMark(mark uint) error { - return errors.New("setting SO_MARK socket option is not supported on this platform") + return ErrMarkNotSupported } diff --git a/utils_windows.go b/utils_windows.go index 198abb5..5a5ba34 100644 --- a/utils_windows.go +++ b/utils_windows.go @@ -4,8 +4,6 @@ package ping import ( - "errors" - "golang.org/x/net/ipv4" "golang.org/x/net/ipv6" ) @@ -29,17 +27,17 @@ func (p *Pinger) matchID(ID int) bool { // SetMark sets the SO_MARK socket option on outgoing ICMP packets. // Setting this option requires CAP_NET_ADMIN. func (c *icmpConn) SetMark(mark uint) error { - return errors.New("setting SO_MARK socket option is not supported on this platform") + return ErrMarkNotSupported } // SetMark sets the SO_MARK socket option on outgoing ICMP packets. // Setting this option requires CAP_NET_ADMIN. func (c *icmpv4Conn) SetMark(mark uint) error { - return errors.New("setting SO_MARK socket option is not supported on this platform") + return ErrMarkNotSupported } // SetMark sets the SO_MARK socket option on outgoing ICMP packets. // Setting this option requires CAP_NET_ADMIN. func (c *icmpV6Conn) SetMark(mark uint) error { - return errors.New("setting SO_MARK socket option is not supported on this platform") + return ErrMarkNotSupported }