267 lines
6.5 KiB
HTML
267 lines
6.5 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>gethostname()--Retrieve Host Name</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 -->
|
||
|
<!-- Edited by Kersten Feb 02 -->
|
||
|
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
|
||
|
</head>
|
||
|
<body>
|
||
|
<!--End Header Records -->
|
||
|
<!-- Java sync-link -->
|
||
|
<script type="text/javascript" language="Javascript" src="../rzahg/synch.js">
|
||
|
</script>
|
||
|
|
||
|
<a name="Top_Of_Page"></a>
|
||
|
|
||
|
<h2>gethostname()--Retrieve Host Name</h2>
|
||
|
|
||
|
<div class="box" style="width: 70%;">
|
||
|
<br>
|
||
|
BSD 4.3 Syntax<br>
|
||
|
<pre>
|
||
|
#include <sys/types.h>
|
||
|
#include <sys/socket.h>
|
||
|
|
||
|
int gethostname(char *<em>name</em>,
|
||
|
int <em>length</em>)
|
||
|
</pre>
|
||
|
|
||
|
<br>
|
||
|
Service Program Name: QSOSRV1<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
Default Public Authority: *USE<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
Threadsafe: Yes<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
</div>
|
||
|
|
||
|
<br>
|
||
|
|
||
|
|
||
|
<div class="box" style="width: 70%;">
|
||
|
<br>
|
||
|
<a href="_xopen_source.htm">UNIX 98 Compatible Syntax</a><br>
|
||
|
|
||
|
|
||
|
<pre>
|
||
|
#define _XOPEN_SOURCE 520
|
||
|
#include <sys/socket.h>
|
||
|
|
||
|
int gethostname(char *<em>name</em>,
|
||
|
socklen_t <em>length</em>)
|
||
|
</pre>
|
||
|
|
||
|
<br>
|
||
|
Service Program Name: QSOSRV1<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
Default Public Authority: *USE<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
Threadsafe: Yes<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
</div>
|
||
|
|
||
|
<br>
|
||
|
|
||
|
|
||
|
<p>The <em>gethostname()</em> function is used to retrieve the name of the host
|
||
|
from the system.</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>name</strong></dt>
|
||
|
|
||
|
<dd>(Output) The pointer to a character array where the host name is to be
|
||
|
stored. The host name is NULL-terminated unless the length of the host name
|
||
|
exceeds the length of the <em>name</em> parameter, in which case the host name
|
||
|
is truncated to the size of the <em>name</em> parameter.<br>
|
||
|
<br>
|
||
|
</dd>
|
||
|
|
||
|
<dt><strong>length</strong></dt>
|
||
|
|
||
|
<dd>(Input) The length of the <em>name</em> parameter.</dd>
|
||
|
</dl>
|
||
|
|
||
|
<br>
|
||
|
<h3>Authorities</h3>
|
||
|
|
||
|
<p>No authorization is required.</p>
|
||
|
|
||
|
<br>
|
||
|
<h3>Return Value</h3>
|
||
|
|
||
|
<p><em>gethostname()</em> returns an integer. Possible values are:</p>
|
||
|
|
||
|
<ul>
|
||
|
<li>-1 (unsuccessful)<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>0 (successful)</li>
|
||
|
</ul>
|
||
|
|
||
|
<br>
|
||
|
|
||
|
|
||
|
<h3>Error Conditions</h3>
|
||
|
|
||
|
<p>When <em>gethostname()</em> fails, <em>errno</em> can be set to one of the
|
||
|
following:</p>
|
||
|
|
||
|
<table cellpadding="5">
|
||
|
<!-- cols="15 85" -->
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[EFAULT]</em></td>
|
||
|
<td align="left" valign="top">Bad address.
|
||
|
|
||
|
<p>The system detected an address which was not valid while attempting to
|
||
|
access the <em>name</em> parameter.</p>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[EINVAL]</em></td>
|
||
|
<td align="left" valign="top">Parameter not valid.
|
||
|
|
||
|
<p>The <em>length</em> parameter specifies a negative value.</p>
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[EIO]</em></td>
|
||
|
<td align="left" valign="top">Input/output error.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>[EUNKNOWN]</em></td>
|
||
|
<td align="left" valign="top">Unknown system state.</td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
|
||
|
<br>
|
||
|
<br>
|
||
|
<h3>Error Messages</h3>
|
||
|
|
||
|
<table width="100%" cellpadding="5">
|
||
|
<!-- cols="15 85" -->
|
||
|
<tr>
|
||
|
<th align="left" valign="top">Message ID</th>
|
||
|
<th align="left" valign="top">Error Message Text</th>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td width="15%" valign="top">CPE3418 E</td>
|
||
|
<td width="85%" valign="top">Possible APAR condition or hardware failure.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top">CPF9872 E</td>
|
||
|
<td align="left" valign="top">Program or service program &1 in library
|
||
|
&2 ended. Reason code &3.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top">CPFA081 E</td>
|
||
|
<td align="left" valign="top">Unable to set return value or error code.</td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
|
||
|
<br>
|
||
|
<br>
|
||
|
<h3>Usage Notes</h3>
|
||
|
|
||
|
<ol>
|
||
|
<li>Maximum length of host names is defined by {MAXHOSTNAMELEN} (defined in
|
||
|
<strong><sys/param.h></strong>).<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>When a process issues a <em>sethostname()</em>, the host name can be
|
||
|
accessed by any process that issues a <em>gethostname()</em>.<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>On an initial program load, the host name is set to whatever was configured
|
||
|
using the iSeries Navigator or
|
||
|
option 12 (Change TCP/IP
|
||
|
domain information) on the Configure TCP/IP (CFGTCP) menu. The local domain
|
||
|
name is appended with the local host name and stored in system-wide storage.
|
||
|
This combined name is the host name that can be retrieved by
|
||
|
<em>gethostname()</em>. If the local host name and local domain name are not
|
||
|
set, the host name is set to NULL.<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>The host name is returned in the default coded character set identifier
|
||
|
(CCSID) currently in effect for the job.<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>gethostname()</em> API is mapped to
|
||
|
<em>qso_gethostname98()</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="shostn.htm">sethostname()</a>--Set Host Name<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li><a href="ghosti.htm">gethostid()</a>--Retrieve Host ID Address<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li><a href="shosti.htm">sethostid()</a>--Set Host ID Address</li>
|
||
|
</ul>
|
||
|
|
||
|
<br>
|
||
|
<hr>
|
||
|
API introduced: V3R1
|
||
|
|
||
|
<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>
|
||
|
|