248 lines
6.2 KiB
HTML
248 lines
6.2 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>inet_addr()--Translate Full Address to 32-bit IP Address</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 -->
|
|
<a name="Top_Of_Page"></a> <!--Java sync-link-->
|
|
<script type="text/javascript" language="Javascript" src="../rzahg/synch.js">
|
|
</script>
|
|
|
|
<h2>inet_addr()--Translate Full Address to 32-bit IP Address</h2>
|
|
|
|
<div class="box" style="width: 70%;">
|
|
<br>
|
|
BSD 4.3 Syntax<br>
|
|
<pre>
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
|
|
unsigned long inet_addr(char *<em>address_string</em>)
|
|
</pre>
|
|
|
|
<br>
|
|
Service Program Name: QSOSRV2<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 <arpa/inet.h>
|
|
|
|
in_addr_t inet_addr(const char *<em>address_string</em>)
|
|
</pre>
|
|
|
|
<br>
|
|
Service Program Name: QSOSRV2<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
Default Public Authority: *USE<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
Threadsafe: Yes<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
</div>
|
|
|
|
<br>
|
|
|
|
|
|
<p>The <em>inet_addr()</em> function is used to translate an Internet address
|
|
from dotted decimal format to a 32-bit IP address.</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>address_string</strong></dt>
|
|
|
|
<dd>(Input) The Internet address in dotted decimal format that is to be
|
|
converted to a 32-bit IP address.</dd>
|
|
</dl>
|
|
|
|
<br>
|
|
|
|
|
|
<h3>Authorities</h3>
|
|
|
|
<p>No authorization is required.</p>
|
|
|
|
<br>
|
|
<h3>Return Value</h3>
|
|
|
|
<p><em>inet_addr()</em> returns an integer. Possible values are:</p>
|
|
|
|
<ul>
|
|
<li>-1 (unsuccessful)</li>
|
|
|
|
<li>n (where n is the 32-bit IP address)</li>
|
|
</ul>
|
|
|
|
|
|
<p>The <em>inet_addr()</em> subroutine returns an error value of -1 for strings
|
|
that are not valid.</p>
|
|
|
|
<p><strong>Note:</strong> An Internet address with a dot notation value of
|
|
255.255.255.255 or its equivalent in a different base format causes the
|
|
<em>inet_addr()</em> subroutine to return an unsigned long value of 4294967295.
|
|
This value is identical to the unsigned representation of the error value.
|
|
Otherwise, the <em>inet_addr()</em> subroutine considers 255.255.255.255 a
|
|
valid Internet address.</p>
|
|
|
|
<br>
|
|
|
|
|
|
<h3>Error Conditions</h3>
|
|
<p>When <em>inet_addr()</em> fails, <em>errno</em> can be set to one of the
|
|
following:</p>
|
|
<dl>
|
|
<dt><em>[EFAULT]</em></dt>
|
|
<dd><p>Bad address.</p>
|
|
|
|
<p>The system detected an address which was not valid while attempting to
|
|
access the <em>address_string</em> parameter.</p></dd>
|
|
|
|
<dt><em>[EINVAL]</em></dt>
|
|
<dd><p>Parameter not valid.</p></dd>
|
|
</dl>
|
|
|
|
<br>
|
|
|
|
<h3>Usage Notes</h3>
|
|
|
|
<ol>
|
|
<li>Notation of the dotted decimal address string can be in one of seven
|
|
formats:
|
|
|
|
<ul>
|
|
<li>Format 1 - a.b.c.d</li>
|
|
|
|
<li>Format 2 - a.b.c.</li>
|
|
|
|
<li>Format 3 - a.b.c</li>
|
|
|
|
<li>Format 4 - a.b.</li>
|
|
|
|
<li>Format 5 - a.b</li>
|
|
|
|
<li>Format 6 - a.</li>
|
|
|
|
<li>Format 7 - a</li>
|
|
</ul>
|
|
|
|
<p>Where a component of the dotted decimal format can be decimal (for example,
|
|
7.3), octal (for example, 07.3) or hexadecimal (for example, 0xb.3).</p>
|
|
|
|
<p>The rules for converting a dotted decimal string are as follows:</p>
|
|
|
|
<ul>
|
|
<li>For format 1, each component is interpreted as one byte of the internet
|
|
address.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>For format 2, each component is interpreted as one byte of the internet
|
|
address, and the rightmost byte is set to zero.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>For format 3, each component is interpreted as one byte of the internet
|
|
address, except for component c, which is interpreted as the rightmost two
|
|
bytes of the internet address.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>For format 4, each component is interpreted as one byte of the internet
|
|
address, and the rightmost two bytes are set to zero.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>For format 5, each component is interpreted as one byte of the internet
|
|
address, except for component b, which is interpreted as the rightmost three
|
|
bytes of the internet address.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>For format 6, component a is interpreted as one byte of the internet
|
|
address, and the rightmost three bytes are set to zero.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>For format 7, component a is returned as the internet address.</li>
|
|
</ul>
|
|
|
|
<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>inet_addr()</em>
|
|
API is mapped to <em>qso_inet_addr98()</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>
|
|
</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>
|
|
|