PHP 8.1.28 Released!

socket_getsockname

(PHP 4 >= 4.1.0, PHP 5, PHP 7, PHP 8)

socket_getsockname Interroga il lato locale di un dato socket e restituisce o la combinazione host/porta oppure un percorso Unix in base al tipo di socket

Descrizione

socket_getsockname(resource $socket, string $&indirizzo, int $&porta = ?): bool
Avviso

Questa funzione è SPERIMENTALE. Ovvero, il comportamento di questa funzione, il nome di questa funzione, in definitiva tutto ciò che è documentato qui può cambiare nei futuri rilasci del PHP senza preavviso. Siete avvisati, l'uso di questa funzione è a vostro rischio.

Se il socket dato è di tipo AF_INET oppure AF_INET6, socket_getsockname() restituisce l'indirizzo IP locale nella notazione appropriata (ad esempio 127.0.0.1 oppure fe80::1) nel parametro indirizzo e, se presente il parametro opzionale porta, anche la porta associata.

Se il socket dato è di tipo AF_UNIX, socket_getsockname() restituirà un percorso Unix (ad esempio /var/run/daemon.sock) nel parametro indirizzo.

Nota: La funzione socket_getsockname() non dovrebbe essere usata con socket AF_UNIX creati da socket_accept(). Soltanto i socket creati con socket_connect() o un socket server primario conseguente alla chiamata di socket_bind() restituirà dei valori significativi.

Restituisce true in caso di successo, false in caso di fallimento. socket_getsockname() può anche restituire false se il tipo di socket non è AF_INET, AF_INET6 o AF_UNIX, in questo caso l'ultimo codice di errore del socket non viene aggiornato.

Vedere anche socket_getpeername(), socket_last_error() e socket_strerror().

add a note

User Contributed Notes 1 note

up
1
CXJ
9 years ago
Curiously, getsockname() works for socket_create() and socket_create_pair() Unix-domain (AF_UNIX) sockets if one calls socket_bind() after creation to name the formerly anonymous socket(s).

Using a socket_bind() call also results in a file system "file" (socket, first character 's' in an "ls -l" listing) being created with the given name. Such a "file" will need to be removed explicitly, as closing the socket will not remove it.
To Top