neon/net
Types
An IPv4 or IPv6 address.
This type is opaque. Use ipv4_address, ipv6_address, or
parse_ip_address to construct values.
pub opaque type IpAddress
The IP version to use for a socket.
pub type IpVersion {
Ipv4
Ipv6
}
Constructors
-
Ipv4 -
Ipv6
A port number in the range 0-65535.
This type is opaque. Use port to construct values and port_to_int
to extract the underlying integer.
pub opaque type Port
POSIX error codes.
See the Erlang inet documentation for descriptions of each error code.
pub type Posix {
Eaddrinuse
Eaddrnotavail
Eafnosupport
Ealready
Econnaborted
Econnrefused
Econnreset
Edestaddrreq
Ehostdown
Ehostunreach
Einprogress
Eisconn
Emsgsize
Enetdown
Enetreset
Enetunreach
Enopkg
Enoprotoopt
Enotconn
Enotty
Enotsock
Eproto
Eprotonosupport
Eprototype
Esocktnosupport
Etimedout
Ewouldblock
Exbadport
Exbadseq
Nxdomain
Eacces
Eagain
Ebadf
Ebadmsg
Ebusy
Edeadlk
Edeadlock
Edquot
Eexist
Efault
Efbig
Eftype
Eintr
Einval
Eio
Eisdir
Eloop
Emfile
Emlink
Emultihop
Enametoolong
Enfile
Enobufs
Enodev
Enolck
Enolink
Enoent
Enomem
Enospc
Enosr
Enostr
Enosys
Enotblk
Enotdir
Enotsup
Enxio
Eopnotsupp
Eoverflow
Eperm
Epipe
Erange
Erofs
Eshutdown
Espipe
Esrch
Estale
Etxtbsy
Exdev
}
Constructors
-
Eaddrinuse -
Eaddrnotavail -
Eafnosupport -
Ealready -
Econnaborted -
Econnrefused -
Econnreset -
Edestaddrreq -
Ehostdown -
Ehostunreach -
Einprogress -
Eisconn -
Emsgsize -
Enetdown -
Enetreset -
Enetunreach -
Enopkg -
Enoprotoopt -
Enotconn -
Enotty -
Enotsock -
Eproto -
Eprotonosupport -
Eprototype -
Esocktnosupport -
Etimedout -
Ewouldblock -
Exbadport -
Exbadseq -
Nxdomain -
Eacces -
Eagain -
Ebadf -
Ebadmsg -
Ebusy -
Edeadlk -
Edeadlock -
Edquot -
Eexist -
Efault -
Efbig -
Eftype -
Eintr -
Einval -
Eio -
Eisdir -
Eloop -
Emfile -
Emlink -
Emultihop -
Enametoolong -
Enfile -
Enobufs -
Enodev -
Enolck -
Enolink -
Enoent -
Enomem -
Enospc -
Enosr -
Enostr -
Enosys -
Enotblk -
Enotdir -
Enotsup -
Enxio -
Eopnotsupp -
Eoverflow -
Eperm -
Epipe -
Erange -
Erofs -
Eshutdown -
Espipe -
Esrch -
Estale -
Etxtbsy -
Exdev
Values
pub fn ip_address_to_string(address: IpAddress) -> String
Converts an IP address to its string representation.
pub fn ipv4_address(
a: Int,
b: Int,
c: Int,
d: Int,
) -> Result(IpAddress, Nil)
Creates an IPv4 address from four octets.
Each octet must be in the range 0-255. Returns Error(Nil) if any
octet is out of range.
pub fn ipv6_address(
a: Int,
b: Int,
c: Int,
d: Int,
e: Int,
f: Int,
g: Int,
h: Int,
) -> Result(IpAddress, Nil)
Creates an IPv6 address from eight 16-bit groups.
Each group must be in the range 0-65535. Returns Error(Nil) if any
group is out of range.
// The loopback address ::1
let assert Ok(addr) = ipv6_address(0, 0, 0, 0, 0, 0, 0, 1)
// fe80::1 (link-local)
let assert Ok(addr) = ipv6_address(0xfe80, 0, 0, 0, 0, 0, 0, 1)
// 2001:db8::1 (documentation range)
let assert Ok(addr) = ipv6_address(0x2001, 0x0db8, 0, 0, 0, 0, 0, 1)
pub fn parse_ip_address(
address: String,
) -> Result(IpAddress, Posix)
Parses a string as an IP address.
Accepts both IPv4 (e.g. "127.0.0.1") and IPv6 (e.g. "::1") formats.
pub fn port(num: Int) -> Result(Port, Nil)
Creates a port from an integer.
The value must be in the range 0-65535. Returns Error(Nil) if the
value is out of range.
pub fn posix_to_string(code: Posix) -> String
Converts a POSIX error code to its string representation.