uTools-Manuals/docs/php/socket_getsockname.html
2019-04-28 19:00:34 +08:00

118 lines
5.4 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Queries the local side of the given socket which may either result in host/port or in a Unix filesystem path, dependent on its type</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.socket-getsockname" class="refentry">
<div class="refnamediv">
<h1 class="refname">socket_getsockname</h1>
<p class="verinfo">(PHP 4 &gt;= 4.1.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">socket_getsockname</span> &mdash; <span class="dc-title">Queries the local side of the given socket which may either result in host/port or in a Unix filesystem path, dependent on its type</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.socket-getsockname-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>socket_getsockname</strong></span>
( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$socket</code></span>
, <span class="methodparam"><span class="type">string</span> <code class="parameter reference">&$addr</code></span>
[, <span class="methodparam"><span class="type">int</span> <code class="parameter reference">&$port</code></span>
] ) : <span class="type">bool</span></div>
<blockquote class="note"><p><strong class="note">Note</strong>:
<span class="simpara">
<span class="function"><strong>socket_getsockname()</strong></span> should not be used with
<strong><code>AF_UNIX</code></strong> sockets created with <span class="function"><a href="socket_connect.html" class="function">socket_connect()</a></span>.
Only sockets created with <span class="function"><a href="socket_accept.html" class="function">socket_accept()</a></span> or a primary
server socket following a call to <span class="function"><a href="socket_bind.html" class="function">socket_bind()</a></span> will return
meaningful values.
</span>
</p></blockquote>
</div>
<div class="refsect1 parameters" id="refsect1-function.socket-getsockname-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">socket</code></dt>
<dd>
<p class="para">
A valid socket resource created with <span class="function"><a href="socket_create.html" class="function">socket_create()</a></span>
or <span class="function"><a href="socket_accept.html" class="function">socket_accept()</a></span>.
</p>
</dd>
<dt>
<code class="parameter">addr</code></dt>
<dd>
<p class="para">
If the given socket is of type <strong><code>AF_INET</code></strong>
or <strong><code>AF_INET6</code></strong>, <span class="function"><strong>socket_getsockname()</strong></span>
will return the local <em class="emphasis">IP address</em> in appropriate notation (e.g.
<em>127.0.0.1</em> or <em>fe80::1</em>) in the
<code class="parameter">address</code> parameter and, if the optional
<code class="parameter">port</code> parameter is present, also the associated port.
</p>
<p class="para">
If the given socket is of type <strong><code>AF_UNIX</code></strong>,
<span class="function"><strong>socket_getsockname()</strong></span> will return the Unix filesystem
path (e.g. <em>/var/run/daemon.sock</em>) in the
<code class="parameter">address</code> parameter.
</p>
</dd>
<dt>
<code class="parameter">port</code></dt>
<dd>
<p class="para">
If provided, this will hold the associated port.
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.socket-getsockname-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
成功时返回 <strong><code>TRUE</code></strong> 或者在失败时返回 <strong><code>FALSE</code></strong><span class="function"><strong>socket_getsockname()</strong></span> may also return
<strong><code>FALSE</code></strong> if the socket type is not any of <strong><code>AF_INET</code></strong>,
<strong><code>AF_INET6</code></strong>, or <strong><code>AF_UNIX</code></strong>, in which
case the last socket error code is <em class="emphasis">not</em> updated.
</p>
</div>
<div class="refsect1 seealso" id="refsect1-function.socket-getsockname-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="socket_getpeername.html" class="function" rel="rdfs-seeAlso">socket_getpeername()</a> - Queries the remote side of the given socket which may either result in host/port or in a Unix filesystem path, dependent on its type</span></li>
<li class="member"><span class="function"><a href="socket_last_error.html" class="function" rel="rdfs-seeAlso">socket_last_error()</a> - Returns the last error on the socket</span></li>
<li class="member"><span class="function"><a href="socket_strerror.html" class="function" rel="rdfs-seeAlso">socket_strerror()</a> - Return a string describing a socket error</span></li>
</ul>
</p>
</div>
</div></div></div></body></html>