148 lines
3.7 KiB
HTML
148 lines
3.7 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>htons()--Convert Short Integer to Network Byte Order</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: -->
|
|
<!-- YYMMDD USERID Change description -->
|
|
<!-- 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>htons()--Convert Short Integer to Network Byte Order</h2>
|
|
|
|
<div class="box" style="width: 70%;">
|
|
<br>
|
|
BSD 4.3 Syntax<br>
|
|
<pre>
|
|
#include <sys/types.h>
|
|
#include <netinet/in.h>
|
|
|
|
unsigned short htons(unsigned short <em>host_short</em>)
|
|
</pre>
|
|
|
|
<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 <netinet/in.h>
|
|
|
|
uint16_t htons(uint16_t <em>host_short</em>)
|
|
</pre>
|
|
|
|
<br>
|
|
Threadsafe: Yes<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
</div>
|
|
|
|
<br>
|
|
<p>The <em>htons()</em> function is used to convert a short (2-byte) integer
|
|
from the local host byte order to standard network byte order.</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>host_short</strong></dt>
|
|
|
|
<dd>(Input) The 2-byte integer in local host byte order that is to be converted
|
|
to standard network byte order.</dd>
|
|
</dl>
|
|
|
|
<br>
|
|
<h3>Authorities</h3>
|
|
|
|
<p>No authorization is required.</p>
|
|
|
|
<br>
|
|
|
|
|
|
<h3>Return Value</h3>
|
|
|
|
<p><em>htons()</em> returns an integer. Possible values are:</p>
|
|
<ul>
|
|
<li>n (where n is the 2-byte integer in standard network byte order)</li>
|
|
</ul>
|
|
|
|
|
|
<br>
|
|
<h3>Usage Notes</h3>
|
|
|
|
<ol>
|
|
<li>On the iSeries server, the value returned to the caller will be the same as
|
|
the value that was passed to <em>htons()</em>, since the local host byte order
|
|
does not differ from the standard network byte order.</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="ntohs.htm">ntohs()</a>--Convert Short Integer to Host Byte
|
|
Order<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="htonl.htm">htonl()</a>--Convert Long Integer to Network Byte
|
|
Order<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="ntohl.htm">ntohl()</a>--Convert Long Integer to Host Byte
|
|
Order</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>
|
|
|