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

search for in the

socket_import_stream> <socket_getpeername
[edit] Last updated: Fri, 23 Mar 2012

view this page in

socket_getsockname

(PHP 4 >= 4.1.0, PHP 5)

socket_getsocknameBelirtilen soketin yerel tarafını sorgulayıp soket türüne göre ya bir konak/port çifti ya da bir Unix dosya yolu döndürür

Açıklama

bool socket_getsockname ( resource $soket , string &$adres [, int &$port ] )

Bilginize: socket_getsockname() işlevi socket_connect() ile oluşturulan AF_UNIX soketlerle kullanılmamalıdır. Sadece socket_accept() ile oluşturulan soketler ve socket_bind() çağrısından sonra bir birincil sunucu soketi için anlamlı bir değer döner.

Değiştirgeler

soket

socket_create() veya socket_accept() ile oluşturulmuş geçerli bir soket özkaynağı.

adres

Belirtilen soket AF_INET veya AF_INET6 türündeyse socket_getsockname() işlevi, bu değiştirgede bir IP adresi (127.0.0.1 veya fe80::1 gibi) ve port değiştirgesinde de belirtilmişse ilgili port numarasını döndürür.

Belirtilen soket AF_UNIX türündeyse bu değiştirgede (/var/run/daemon.sock gibi) bir Unix dosya yolu döner.

port

Belirtilmişse ilgili port değeri bu değiştirgeye konur.

Dönen Değerler

Başarı durumunda TRUE, başarısızlık durumunda FALSE döner. Soket AF_INET, AF_INET6 veya AF_UNIX türünde değilse işlev FALSE döndürebilir, ancak böyle bir durumda son soket hata kodu güncellenmez.

Ayrıca Bakınız

  • socket_getpeername() - Belirtilen soketin yerel tarafını sorgulayıp soket türüne göre ya bir konak/port çifti ya da bir Unix dosya yolu döndürür
  • socket_last_error() - Soket üzerindeki son hatanın kodunu döndürür
  • socket_strerror() - Bir soket hatasıyla ilgili açıklamayı döndürür



add a note add a note User Contributed Notes socket_getsockname
not at valid dot com 13-Oct-2007 06:35
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