Rust

net

Module

Network helpers: inet_pton/inet_ntop.

PHPRust
inet_pton($ip)inet_pton
inet_ntop($ip)inet_ntop

PHP's address functions call the C library; the dev image is Alpine, so these are ports of musl's inet_pton/inet_ntop (src/network/), whose IPv6 formatting differs from glibc's in which zero run it compresses.

Every function here is checked against the real PHP function by bin/compat fuzz php-std (operations net.*).

Contents

use php_std::net::NulByteError;
Rust
pub struct NulByteError

PHP's ValueError for a string argument that must not contain NUL bytes (Z_PARAM_PATH): "<function>(): Argument #1 ($ip) must not contain any null bytes".

Also implements Display.
use php_std::net::PackedAddr;
Rust
pub enum PackedAddr

A packed address from inet_pton.

use php_std::net::inet_ntop;
Rust
pub fn inet_ntop(packed: &[u8]) -> Option<String>

PHP inet_ntop($ip): a 4-byte (IPv4) or 16-byte (IPv6) packed address in text form; None (PHP's false) for any other length.

use php_std::net::inet_pton;
Rust
pub fn inet_pton(ip: &[u8]) -> Result<Option<PackedAddr>, NulByteError>

PHP inet_pton($ip): IPv6 when the string contains :, IPv4 when it contains ., None (PHP's false) otherwise or when invalid.