244 lines
6.6 KiB
HTML
244 lines
6.6 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<meta name="Copyright" content="Copyright (c) 2006 by IBM Corporation">
|
|
<title>getservbyport()--Get Service Name for Port Number</title>
|
|
<!-- Begin Header Records ========================================== -->
|
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
|
<!-- US Government Users Restricted Rights -->
|
|
<!-- Use, duplication or disclosure restricted by -->
|
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
|
<!-- Change History: -->
|
|
<!-- Unix8 SCRIPT J converted by B2H R4.1 (346) (CMS) by V2KEA304 -->
|
|
<!-- at RCHVMW2 on 17 Feb 1999 at 11:05:09 -->
|
|
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
|
|
</head>
|
|
<body>
|
|
<!--End Header Records --><!-- Edited by Kersten Feb 02 -->
|
|
<!-- Java sync-link -->
|
|
<script type="text/javascript" language="Javascript" src="../rzahg/synch.js">
|
|
</script>
|
|
|
|
<a name="Top_Of_Page"></a>
|
|
|
|
<h2>getservbyport()--Get Service Name for Port Number</h2>
|
|
|
|
<div class="box" style="width: 80%;">
|
|
<br>
|
|
BSD 4.3 Syntax<br>
|
|
<pre>
|
|
#include <netdb.h>
|
|
|
|
struct servent *getservbyport(int <em>port_number</em>,
|
|
char *<em>protocol_name</em>)
|
|
</pre>
|
|
|
|
<br>
|
|
Service Program Name: QSOSRV2<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
Default Public Authority: *USE<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
Threadsafe: No; see <a href="#USAGE_NOTES">Usage Notes</a>.<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
</div>
|
|
|
|
<br>
|
|
|
|
<div class="box" style="width: 80%;">
|
|
<br>
|
|
<a href="_xopen_source.htm">UNIX 98 Compatible Syntax</a><br>
|
|
<pre>
|
|
#define _XOPEN_SOURCE 520
|
|
#include <netdb.h>
|
|
|
|
struct servent *getservbyport(int <em>port_number</em>,
|
|
const char *<em>protocol_name</em>)
|
|
</pre>
|
|
|
|
<br>
|
|
Service Program Name: QSOSRV2<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
Default Public Authority: *USE<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
Threadsafe: No; see <a href="#USAGE_NOTES">Usage Notes</a>.<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
</div>
|
|
|
|
<br>
|
|
|
|
|
|
<p>The <em>getservbyport()</em> function is used to retrieve information about
|
|
a service assigned to a port number. The information is retrieved from the
|
|
service database file.</p>
|
|
|
|
<p>There are two versions of the API, as shown above. The base i5/OS API uses BSD 4.3
|
|
structures and syntax. The other uses syntax and structures compatible with the UNIX 98
|
|
programming interface specifications. You can select the UNIX 98 compatible
|
|
interface with the <a href="_xopen_source.htm">_XOPEN_SOURCE</a> macro.</p>
|
|
|
|
<br>
|
|
|
|
|
|
<h3>Parameters</h3>
|
|
|
|
<dl>
|
|
<dt><strong>port_number</strong></dt>
|
|
|
|
<dd>(Input) The port number for which service information is to be
|
|
retrieved.<br>
|
|
<br>
|
|
</dd>
|
|
|
|
<dt><strong>protocol_name</strong></dt>
|
|
|
|
<dd>(Input) The pointer to the character string that contains the name of the
|
|
protocol that further qualifies the search criteria. For example, if the
|
|
<em>port_number</em> is 10, and the <em>protocol_name</em> is tcp, then the
|
|
call will return the server that uses the TCP protocol on port number 10. If
|
|
this parameter is set to NULL, then the first server is returned, regardless of
|
|
the protocol used.</dd>
|
|
</dl>
|
|
|
|
<br>
|
|
<h3>Authorities</h3>
|
|
|
|
<p>No authorization is required.</p>
|
|
|
|
<br>
|
|
|
|
|
|
<h3>Return Value</h3>
|
|
|
|
<p><em>getservbyport()</em> returns a pointer. Possible values are:</p>
|
|
|
|
<ul>
|
|
<li>NULL (unsuccessful)<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>p (successful), where p is a pointer to <strong>struct
|
|
servent</strong>.</li>
|
|
</ul>
|
|
|
|
|
|
<p>The structure <strong>struct servent</strong> is defined in
|
|
<strong><netdb.h></strong>.</p>
|
|
|
|
<pre>
|
|
struct servent {
|
|
char *s_name;
|
|
char **s_aliases;
|
|
int s_port;
|
|
char *s_proto
|
|
};
|
|
</pre>
|
|
|
|
<p><em>s_name</em> points to the character string that contains the name of the
|
|
service. <em>s_aliases</em> is a pointer to a NULL-terminated array of
|
|
alternate names for the service. <em>s_port</em> is the port number assigned to
|
|
the service. <em>s_proto</em> is the protocol being used by the service.</p>
|
|
|
|
<br>
|
|
<h3><a name="USAGE_NOTES">Usage Notes</a></h3>
|
|
|
|
<ol>
|
|
<li>The iSeries Navigator or the following CL commands can be
|
|
used to access the services database file:<br>
|
|
<br>
|
|
<ul>
|
|
<li>WRKSRVTBLE (Work with Service Table Entries)<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>ADDSRVTBLE (Add Service Table Entry)<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>RMVSRVTBLE (Remove Service Table Entry)</li>
|
|
</ul>
|
|
|
|
<br>
|
|
</li>
|
|
|
|
<li>The pointer returned by <em>getservbyport()</em> points to static storage
|
|
that is overwritten on subsequent calls to the <em>getservbyport()</em>,
|
|
<em>getservbyname()</em>, or <em>getservent()</em> functions.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>When the service information is obtained from the service database file,
|
|
the file is opened and the service information is retrieved (if it exists) from
|
|
the file. The file is then closed only if a <em>setservent()</em> with a
|
|
nonzero parameter value was not previously done.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>A coded character set identifier (CCSID) of 65535 for the job requests that
|
|
no database translation be performed. For translation to occur for the protocol
|
|
name specified by the <em>protocol_name</em> parameter, or for the service
|
|
names returned in the servent structure, the job CCSID must be something other
|
|
than 65535.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>Do not use the <em>getservbyport()</em> function in a multithreaded
|
|
environment. See the multithread alternative <em>getservbyport_r()</em>
|
|
function.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>When you develop in C-based languages and an application is compiled with the _XOPEN_SOURCE
|
|
macro defined to the value 520 or greater, the <em>getservbyport()</em> API is mapped to
|
|
<em>qso_getservbyport98()</em>.</li>
|
|
</ol>
|
|
|
|
<br>
|
|
<h3>Related Information</h3>
|
|
|
|
<ul>
|
|
<li><a href="_xopen_source.htm">_XOPEN_SOURCE</a>--Using _XOPEN_SOURCE for the UNIX 98
|
|
compatible interface<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="gsrvnm.htm">getservbyname()</a>--Get Port Number for Service
|
|
Name<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="gsrvnt.htm">getservent()</a>--Get Next Entry from Service
|
|
Database<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="ssrvnt.htm">setservent()</a>--Open Service Database<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="esrvnt.htm">endservent()</a>--Close Service Database</li>
|
|
</ul>
|
|
|
|
<br>
|
|
<hr>
|
|
API introduced: V4R2
|
|
|
|
<hr>
|
|
<center>
|
|
<table cellpadding="2" cellspacing="2">
|
|
<tr align="center">
|
|
<td valign="middle" align="center"><a href="#Top_Of_Page">Top</a> | <a href=
|
|
"unix.htm">UNIX-Type APIs</a> | <a href="aplist.htm">APIs by category</a> </td>
|
|
</tr>
|
|
</table>
|
|
</center>
|
|
</body>
|
|
</html>
|
|
|