protoent.html

来自「perl教程」· HTML 代码 · 共 94 行

HTML
94
字号
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>Net::protoent - by-name interface to Perl's built-in getproto* functions</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>

<body>

<script>writelinks('__top__',2);</script>
<h1><a>Net::protoent - by-name interface to Perl's built-in getproto* functions</a></h1>
<p><a name="__index__"></a></p>

<!-- INDEX BEGIN -->

<ul>

	<li><a href="#name">NAME</a></li>
	<li><a href="#synopsis">SYNOPSIS</a></li>
	<li><a href="#description">DESCRIPTION</a></li>
	<li><a href="#note">NOTE</a></li>
	<li><a href="#author">AUTHOR</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>Net::protoent - by-name interface to Perl's built-in getproto*() functions</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
 <span class="keyword">use</span> <span class="variable">Net::protoent</span><span class="operator">;</span>
 <span class="variable">$p</span> <span class="operator">=</span> <span class="keyword">getprotobyname</span><span class="operator">(</span><span class="keyword">shift</span> <span class="operator">||</span> <span class="string">'tcp'</span><span class="operator">)</span> <span class="operator">||</span> <span class="keyword">die</span> <span class="string">"no proto"</span><span class="operator">;</span>
 <span class="keyword">printf</span> <span class="string">"proto for %s is %d, aliases are %s\n"</span><span class="operator">,</span>
    <span class="variable">$p</span><span class="operator">-&gt;</span><span class="variable">name</span><span class="operator">,</span> <span class="variable">$p</span><span class="operator">-&gt;</span><span class="variable">proto</span><span class="operator">,</span> <span class="string">"@{$p-&gt;aliases}"</span><span class="operator">;</span>
</pre>
<pre>
 <span class="keyword">use</span> <span class="variable">Net::protoent</span> <span class="string">qw(:FIELDS)</span><span class="operator">;</span>
 <span class="keyword">getprotobyname</span><span class="operator">(</span><span class="keyword">shift</span> <span class="operator">||</span> <span class="string">'tcp'</span><span class="operator">)</span> <span class="operator">||</span> <span class="keyword">die</span> <span class="string">"no proto"</span><span class="operator">;</span>
 <span class="keyword">print</span> <span class="string">"proto for $p_name is $p_proto, aliases are @p_aliases\n"</span><span class="operator">;</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>This module's default exports override the core getprotoent(),
getprotobyname(), and <code>getnetbyport()</code> functions, replacing them with
versions that return &quot;Net::protoent&quot; objects.  They take default
second arguments of &quot;tcp&quot;.  This object has methods that return the
similarly named structure field name from the C's protoent structure
from <em>netdb.h</em>; namely name, aliases, and proto.  The aliases method
returns an array reference, the rest scalars.</p>
<p>You may also import all the structure fields directly into your namespace
as regular variables using the :FIELDS import tag.  (Note that this still
overrides your core functions.)  Access these fields as variables named
with a preceding <code>p_</code>.  Thus, <code>$proto_obj-&gt;name()</code> corresponds to
$p_name if you import the fields.  Array references are available as
regular array variables, so for example <code>@{ $proto_obj-&gt;aliases()
}</code> would be simply @p_aliases.</p>
<p>The <code>getproto()</code> function is a simple front-end that forwards a numeric
argument to getprotobyport(), and the rest to getprotobyname().</p>
<p>To access this functionality without the core overrides,
pass the <a href="../../lib/Pod/perlfunc.html#item_use"><code>use</code></a> an empty import list, and then access
function functions with their full qualified names.
On the other hand, the built-ins are still available
via the <code>CORE::</code> pseudo-package.</p>
<p>
</p>
<hr />
<h1><a name="note">NOTE</a></h1>
<p>While this class is currently implemented using the Class::Struct
module to build a struct-like class, you shouldn't rely upon this.</p>
<p>
</p>
<hr />
<h1><a name="author">AUTHOR</a></h1>
<p>Tom Christiansen</p>

</body>

</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?