Documentation
¶
Overview ¶
Copyright © 2024 Mikael Schultz <mikael@conf-t.se>
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 <mikael@conf-t.se>
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 IPv4ToBinary(ipStr string) string
- func IPv4ToDecimal(ipStr string) string
- func IPv4ToHex(ipStr string) string
- func IPv4ToInt(ipStr string) uint32
- func IntToIPv4(ipInt uint32) string
- func IsIPv4(s string) bool
- func IsIPv4Hex(hexIP string) bool
- func IsIPv6(s string) bool
- func NetmaskPrefixLength(mask string) (int, error)
- func ParseIP(s string) (net.IP, *net.IPNet, error)
- func ParseIPv4FromHex(hexIP string) (string, error)
- func ResolveIP(hostname string) (string, 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) Split(bits int) ([]*IPv4, error)
- func (ip *IPv4) String() string
- func (ip *IPv4) UsableHosts() uint32
- func (ip *IPv4) Wildcard() string
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidHexAddress = errors.New("invalid hexadecimal IPv4 address")
var ErrInvalidNetmask = errors.New("invalid netmask")
Functions ¶
func IPv4ToBinary ¶ added in v1.1.0
IPv4ToBinary is a function that takes an IPv4 address in dotted-decimal notation as input and returns the IP address in binary notation.
func IPv4ToDecimal ¶ added in v1.1.0
IPv4ToDecimal is a function that takes an IPv4 address in dotted-decimal notation as input and returns the IP address in decimal notation (integer).
func IPv4ToHex ¶ added in v1.1.0
IPv4ToHex is a function that takes an IPv4 address in dotted-decimal notation as input and returns the IP address in hexadecimal notation.
func IPv4ToInt ¶ added in v1.2.0
IPv4ToInt is a function that takes an IPv4 address in dotted-decimal notation as input and returns the IP address in decimal notation (integer).
func IntToIPv4 ¶ added in v1.2.0
IntToIPv4 is a function that takes an IP address in decimal notation (integer) as input and returns the IP address in dotted-decimal notation.
func IsIPv4Hex ¶ added in v1.1.0
IsHexIPv4 is a function that takes a string as input and returns true if the string is a valid hexadecimal IPv4 address. Otherwise it returns false.
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
func ParseIP ¶
Function that takes a string as input and returns an IP address and a subnet mask as output.
func ParseIPv4FromHex ¶ added in v1.1.0
ParseIPv4FromHex is a function that takes a string as input and returns an IPv4 address in dotted-decimal notation. The input string must be a valid hexadecimal IPv4 address.
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" - "0xXXXXXXXX/Y" - "0xXXXXXXXX Y" - "0xXXXXXXXX" - "XXXXXXXX/Y" - "XXXXXXXX Y" - "XXXXXXXX" - "XXXXXXXX XXXXXXXX/
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) Split ¶ added in v1.2.0
Split is a function that takes an IPv4 address and a number of bits as input and returns a list of subnets as output.
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