Documentation
¶
Overview ¶
Copyright © 2024 Mikael Schultz <bitcanon@proton.me>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright © 2024 Mikael Schultz <bitcanon@proton.me>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Index ¶
- Variables
- func IsIPv4(s string) bool
- func IsIPv6(s string) bool
- func NetmaskPrefixLength(mask string) (int, error)
- func ParseIP(s string) (net.IP, *net.IPNet, error)
- type IPv4
- func (ip *IPv4) Address() string
- func (ip *IPv4) Broadcast() string
- func (ip *IPv4) FirstHost() string
- func (ip *IPv4) LastHost() string
- func (ip *IPv4) Netmask() string
- func (ip *IPv4) Network() string
- func (ip *IPv4) NetworkSize() uint32
- func (ip *IPv4) PrefixLength() int
- func (ip *IPv4) String() string
- func (ip *IPv4) UsableHosts() uint32
- func (ip *IPv4) Wildcard() string
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidNetmask = errors.New("invalid netmask")
Functions ¶
func NetmaskPrefixLength ¶
NetmaskPrefixLength is a function that takes a netmask in dotted-decimal notation (e.g. 255.255.255.0) as input and returns the number of bits set in the netmask
Types ¶
type IPv4 ¶
The IPv4 struct represents an IPv4 address as an IP address, a subnet mask and a network address. It also contains functions for calculating the broadcast address, the first and last usable host addresses, the number of usable hosts and the size of the network in number of IP addresses.
func ParseIPv4 ¶
ParseIPv4 is a function that takes a string as input and returns an IPv4 address and a subnet mask as output. The input string can be in the following formats: - "X.X.X.X/Y" - "X.X.X.X Y" - "X.X.X.X"
func (*IPv4) FirstHost ¶
FirstHost is a function that returns the first usable host address in the network
func (*IPv4) LastHost ¶
LastHost is a function that returns the last usable host address in the network
func (*IPv4) NetworkSize ¶
NetworkSize is a function that returns the size of the network in number of IP addresses
func (*IPv4) PrefixLength ¶
PrefixLength is a function that returns the number of bits set in the netmask
func (*IPv4) String ¶
String is a function that returns the IP address and the prefix length in CIDR notation
func (*IPv4) UsableHosts ¶
UsableHosts is a function that returns the number of usable hosts in the network