-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathposition.go
25 lines (20 loc) · 879 Bytes
/
position.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Copyright 2015 Mikio Hara. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE.
package ipaddr
import "net"
// A Position represents a position on IP address space.
type Position struct {
IP net.IP // IP address
Prefix Prefix // IP address prefix
}
// IsBroadcast reports whether p is an IPv4 directed or limited
// broadcast address.
func (p *Position) IsBroadcast() bool {
return !p.IP.IsUnspecified() && !p.IP.IsMulticast() && p.IP.To4() != nil && (p.IP.Equal(net.IPv4bcast) || p.IP.Equal(p.Prefix.Last()))
}
// IsSubnetRouterAnycast reports whether p is an IPv6 subnet router
// anycast address.
func (p *Position) IsSubnetRouterAnycast() bool {
return !p.IP.IsUnspecified() && !p.IP.IsLoopback() && !p.IP.IsMulticast() && p.IP.To16() != nil && p.IP.To4() == nil && p.IP.Equal(p.Prefix.IP)
}