Skip to content

gethostbyaddr outputs binary string #7748

Closed

Description

@RobertEcker

Description

PHP 8.1.0
The following code:

<?php
var_dump(gethostbyaddr('89.222.225.0'));
var_dump(gethostbyaddr('192.88.99.1'));

Resulted in this output:
Snap1

But I expected this output instead:

string(12) "89.222.225.0" (which is still shown when I use PHP 8.0.3)
string(12) "192.88.99.1"

PHP Version

PHP 8.1.0

Operating System

Windows 10 (x64)

Activity

  1. Gemorroj commented on Dec 10, 2021

    @Gemorroj
    Contributor

    I can confirm issue on Win10 x64

    PS C:\Users\wapin> php -v
    PHP 8.0.13 (cli) (built: Nov 16 2021 21:58:37) ( ZTS Visual C++ 2019 x64 )
    Copyright (c) The PHP Group
    Zend Engine v4.0.13, Copyright (c) Zend Technologies
        with Zend OPcache v8.0.13, Copyright (c), by Zend Technologies
        with Xdebug v3.1.2, Copyright (c) 2002-2021, by Derick Rethans
    PS C:\Users\wapin> php -a
    Interactive shell
    
    php > var_dump(gethostbyaddr('89.222.225.0'));
    php shell code:1:
    string(12) "89.222.225.0"
    php > var_dump(gethostbyaddr('192.88.99.1'));
    php shell code:1:
    string(11) "192.88.99.1"
    
    PS S:\php81> ./php -v
    PHP 8.1.0 (cli) (built: Nov 23 2021 21:48:28) (ZTS Visual C++ 2019 x64)
    Copyright (c) The PHP Group
    Zend Engine v4.1.0, Copyright (c) Zend Technologies
    PS S:\php81> ./php -a
    Interactive shell
    
    php > var_dump(gethostbyaddr('89.222.225.0'));
    string(0) ""
    php > var_dump(gethostbyaddr('192.88.99.1'));
    string(0) ""
    
  2. RobertEcker commented on Dec 10, 2021

    @RobertEcker
    Author

    it also depends somehow from the previous (working) result

    <?php
    var_dump(gethostbyaddr('80.1.2.3'));
    var_dump(gethostbyaddr('89.222.225.0'));
    var_dump(gethostbyaddr('192.88.99.1'));
    ^Z
    string(49) "cpc99474-lich12-2-0-cust514.3-2.cable.virginm.net"
    string(16) "cpc99474-lich12-"
    string(16) "cpc99474-lich12-"
    
  3. damianwadley commented on Dec 10, 2021

    @damianwadley
    Member

    First thing I see is in the new usage of getnameinfo: the code checks <0 for error but MSDN and getnameinfo(3) lists it as merely returning non-zero.

  4. self-assigned this
    on Dec 10, 2021
  5. added a commit that references this issue on Dec 10, 2021
    7daf012
  6. added a commit that references this issue on Dec 10, 2021
    6606cc0
  7. pierrejoye commented on Feb 12, 2022

    @pierrejoye
    Contributor

    @remicollet what was the reason to use getnameinfo in php_gethostbyaddr instead of gethostbyaddr (which is exactly what this function does)? I can't find discussion or bug # about that change.

    I do like this little quote from various OSes doc, incl. windows one:

    Note The ability to perform reverse DNS lookups using the getnameinfo function is convenient, but such lookups are considered inherently unreliable, and should be used only as a hint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions