downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

socket_import_stream> <socket_getpeername
[edit] Last updated: Fri, 17 May 2013

view this page in

socket_getsockname

(PHP 4 >= 4.1.0, PHP 5)

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

bool socket_getsockname ( resource $socket , string $&indirizzo [, int $&porta ] )
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 add a note User Contributed Notes socket_getsockname - [1 notes]
up
0
not at valid dot com
5 years ago
Just a quick note:
I found socket_getsockname() is not IPv6 compatible or may just return some unexpected results?

<?php
Simple Code Example
:

$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
   
socket_bind($socket,'0.0.0.0',150);

socket_getsockname($socket, $IP, $PORT);

print
$IP.":".$PORT."\n";

?>

This does not print $IP 127.0.0.1 or 192.168.1.1 or even 0.0.0.0 ... etc ... like you would expect ... in my case I receive 10.0.0.0 witch is not a valid port on my system using IPv5 and IPv6! Thus you should rely on using the initial values of socket_bind() to get the local address.

Hope this helps...

 
show source | credits | stats | sitemap | contact | advertising | mirror sites