Skip to content

inet_pton() rejects valid IPv6 addresses #692

Description

@nahime0

Summary

Elephc's native inet_pton() implementation accepts IPv4 but returns false for valid IPv6 addresses. PHP supports both address families and returns a 16-byte packed string for IPv6.

This came up while validating proxy-provided client IP addresses in NativeBin.

Reproducer

<?php

$ipv4 = inet_pton('127.0.0.1');
$ipv6 = inet_pton('2001:4860:4860::8888');

echo is_string($ipv4) ? strlen($ipv4) : -1;
echo "\n";
echo is_string($ipv6) ? strlen($ipv6) : -1;
echo "\n";

Actual behavior

Elephc output:

4
-1

PHP output:

4
16

Expected behavior

Valid IPv6 input should return its 16-byte packed binary representation. Invalid IPv4 or IPv6 input should return false.

Implementation note

The AOT runtime helper is currently documented and implemented as a dotted-quad IPv4 parser in src/codegen_support/runtime/strings/inet_pton.rs, even though the PHP builtin covers IPv4 and IPv6.

Environment

Reproduced on Elephc e47a8e9dab44d3ed08415f115c0f4233adeca0ab. The current remote main only adds a repository-statistics commit after this code revision.

Workaround

NativeBin uses a dedicated IPv6 validator instead of relying on inet_pton() for IPv6 addresses.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions