ip-0.8.3: Library for IP and MAC addresses

Safe HaskellNone
LanguageHaskell2010

Net.IPv4

Contents

Description

An IPv4 data type

This module provides the IPv4 data type and functions for working with it. There are also encoding and decoding functions provided in this module, but they should be imported from Net.IPv4.Text and Net.IPv4.ByteString.Char8 instead. They are defined here so that the FromJSON and ToJSON instances can use them.

At some point, a highly efficient IPv4-to-ByteString function needs to be added to this module to take advantage of aeson's new toEncoding method.

Synopsis

Conversion Functions

fromOctets :: Word8 -> Word8 -> Word8 -> Word8 -> IPv4 Source #

Create an IPv4 address from four octets. The first argument is the most significant octet. The last argument is the least significant.

Since the Show and Read instances for IPv4 are not generally usefully, this function is the recommened way to create IPv4 addresses. For example:

>>> fromOctets 192 168 1 1
IPv4 {getIPv4 = 3232235777}

toOctets :: IPv4 -> (Word8, Word8, Word8, Word8) Source #

Convert an IPv4 address into a quadruple of octets. The first element in the quadruple is the most significant octet. The last element is the least significant octet.

Special IP Addresses

any :: IPv4 Source #

The IP address representing any host: 0.0.0.0

loopback :: IPv4 Source #

The loopback IP address: 127.0.0.1

broadcast :: IPv4 Source #

The broadcast IP address: 127.0.0.1

Range Predicates

private :: IPv4 -> Bool Source #

Checks to see if the IPv4 address belongs to a private network. The three private networks that are checked are 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16.

reserved :: IPv4 -> Bool Source #

Checks to see if the IPv4 address belongs to a reserved network. This includes the three private networks that private checks along with several other ranges that are not used on the public Internet.