Add basic docs to the readme.

This commit is contained in:
James Harton 2017-10-11 18:26:19 +13:00
parent 54e27ff9c8
commit 2e2f81d9c5
2 changed files with 26 additions and 0 deletions

View file

@ -1,5 +1,8 @@
# IP
[![pipeline status](https://gitlab.com/jimsy/ip/badges/master/pipeline.svg)](https://gitlab.com/jimsy/ip/commits/master)
[![Hex.pm](https://img.shields.io/hexpm/v/ip.svg)](https://hex.pm/packages/ip)
IP, IP, Ooray! Simple IP Address representations.
## Installation
@ -15,6 +18,23 @@ def deps do
end
```
## Usage
`ip` provides representations for IP addresses and subnets for Elixir with a bunch of helpful stuff tacked on the side.
iex> "192.0.2.1"
...> |> IP.Address.from_string!
#IP.Address<192.0.2.1 DOCUMENTATION>
iex> "2001:db8::"
...> |> IP.Address.from_string!
#IP.Address<2001:db8:: DOCUMENTATION>
iex> outside = IP.Prefix.from_string!("2001:db8::/64")
...> inside = IP.Prefix.eui_64(outside, "60:f8:1d:ad:d8:90")
...> IP.Prefix.contains_address?(outside, inside)
true
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/ip](https://hexdocs.pm/ip).

View file

@ -273,6 +273,12 @@ defmodule IP.Prefix do
iex> IP.Prefix.from_string!("2001:db8::/64")
...> |> IP.Prefix.contains_address?(IP.Address.from_string!("2001:db8:1::1"))
false
iex> outside = IP.Prefix.from_string!("2001:db8::/64")
...> inside = IP.Prefix.eui_64(outside, "60:f8:1d:ad:d8:90")
...> IP.Prefix.contains_address?(outside, inside)
true
"""
def contains_address?(%Prefix{address: %Address{address: addr0, version: 4}, mask: mask} = _prefix,
%Address{address: addr1, version: 4} = _address)