Skip to content

socket_getsockname returns wrong address on some unix filename #13603

Closed
@jyxjjj

Description

@jyxjjj

Description

The following code:

<?php
        $socket = socket_create(AF_UNIX, SOCK_STREAM, 0);
        socket_bind($socket, 'sn.sock');
        socket_listen($socket);
        socket_getsockname($socket, $address);

Resulted in this output:

sn.sockxxxxxxxx

But I expected this output instead:

sn.sock

There are more binary string when named as sn.sock
(So i will give it all in hex)
something like this in hex: 58b30101
changed every time when re-generate sn.sock: 98f6(strange, this time it only 4 length)

When a.sock: 9098c10301 90d8800101
s.sock: 90186a0301
(changed every time too)

At first i think it is because this string is too short,
Then i tried s.s, it always returned s.s correctly.

I am using 8.3.1 , I haven't done any more testing, but I have the impression that I met this a long time ago, when I was still a newbie. Seems like from PHP5. I don't have such old env, cannot give more test, sorry

PHP Version

8.3.1

Operating System

macOS 14.2.1 23C71

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions