ipip

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2020 License: MIT Imports: 1 Imported by: 2

README

Package ipip (ip is private) checks if a net.IP is a private (local) address according to RFC 1918 for ip4 and RFC 4193 for ip6.

GoDoc Build Status codecov

Install

$ go get -u github.com/audiolion/ipip

Usage


import (
  "github.com/audiolion/ipip"
)

func main() {

  var ip net.IP
  ip = net.IPv4(10, 0, 0, 0)
  
  ipip.IsPrivate(ip) // true
}

Prior Art

ipip is based on the work of Max Semenik with input from Mikio Hara to add this functionality directly in Go's net package. Track the status of this change request here.

FAQ

What about multicast, limited-broadcast, unassigned, and reserved addresses?

The goal of ipip is to implement checking based on RFC 1918 and RFC 4193, and considers these edge cases to be out of scope.

Why did you use IsPrivate instead of IsLocal?

RFC 1918 referred to these ip4 addresses as "private", meaning they are not routable on the public internet. When the same concept was applied to ip6 in RFC 4193 the term "local" address was used. While local is the more correct term, the layman probably is used to talking about "public" vs. "private" addresses and so the private terminology was used.

There is no such thing as a local-untyped address, why not IsPrivateUnicast?

Yes, IsPrivateUnicast would be more technically correct, but the purpose of this package is to distinguish between "public" routable addresses and non-public (private) addresses as defined by RFC 1918 and RFC 4193. Adding "Unicast" makes the name more confusing to the layman, and we clarify unhandled edge cases in the comments and in this faq.

Documentation

Overview

Package ipip (ip is private) checks if a net.IP is a private (local) address according to RFC 1918 and RFC 4193.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPrivate

func IsPrivate(ip net.IP) bool

IsPrivate reports whether ip is a private (local) address.

The identification of private, or local, unicast addresses uses address type indentification as defined in RFC 1918 for ip4 and RFC 4193 for ip6 with the exception of ip4 directed broadcast addresses.

Unassigned, reserved, multicast and limited-broadcast addresses are not handled and will return false.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL