From 2e2f81d9c55228473973b4d76e2a243be3b024c7 Mon Sep 17 00:00:00 2001 From: James Harton Date: Wed, 11 Oct 2017 18:26:19 +1300 Subject: [PATCH] Add basic docs to the readme. --- README.md | 20 ++++++++++++++++++++ lib/ip/prefix.ex | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/README.md b/README.md index 4fe9728..2b1febd 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/lib/ip/prefix.ex b/lib/ip/prefix.ex index a3bd403..9caec7e 100644 --- a/lib/ip/prefix.ex +++ b/lib/ip/prefix.ex @@ -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)