haiku-website/static/legacy-docs/bebook/BNetAddress.html

71 lines
18 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>The Be Book - Classes And Methods - The Network Kit</title><link rel="stylesheet" href="be_book.css" type="text/css" media="all" /><link rel="shortcut icon" type="image/vnd.microsoft.icon" href="./images/favicon.ico" /><!--[if IE]>
<link rel="stylesheet" type="text/css" href="be_book_ie.css" />
<![endif]--><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /><meta name="keywords" content="Access, BeOS, BeBook, API" /><link rel="start" href="index.html" title="The Be Book" /><link rel="up" href="TheNetworkKit.html" title="The Network Kit" /><link rel="prev" href="TheNetworkKit.html" title="The Network Kit" /><link rel="next" href="BNetBuffer.html" title="BNetBuffer" /></head><body><div id="header"><div id="headerT"><div id="headerTL"><a accesskey="p" href="TheNetworkKit.html" title="The Network Kit"><img src="./images/navigation/prev.png" alt="Prev" /></a> <a accesskey="u" href="TheNetworkKit.html" title="The Network Kit"><img src="./images/navigation/up.png" alt="Up" /></a> <a accesskey="n" href="BNetBuffer.html" title="BNetBuffer"><img src="./images/navigation/next.png" alt="Next" /></a></div><div id="headerTR"><div id="navigpeople"><a href="http://www.haiku-os.org"><img src="./images/People_24.png" alt="haiku-os.org" title="Visit The Haiku Website" /></a></div><div class="navighome" title="Home"><a accesskey="h" href="index.html"><img src="./images/navigation/home.png" alt="Home" /></a></div><div class="navigboxed" id="navigindex"><a accesskey="i" href="ClassIndex.html" title="Index">I</a></div><div class="navigboxed" id="naviglang" title="English">en</div></div><div id="headerTC">The Be Book - Classes And Methods - The Network Kit</div></div><div id="headerB">Prev: <a href="TheNetworkKit.html">The Network Kit</a>  Up: <a href="TheNetworkKit.html">The Network Kit</a>  Next: <a href="BNetBuffer.html">BNetBuffer</a></div><hr /></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h2 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BNetAddress"></a>BNetAddress</h2></div></div></div><a id="id1208699" class="indexterm"></a><div class="classheader"><table border="0"><colgroup><col /><col /></colgroup><tbody><tr><td><table width="100%" border="0"><colgroup><col /><col /></colgroup><tbody><tr><td>Derived From:</td><td>None</td></tr><tr><td>Mix-in Classes:</td><td><a class="link" href="BArchivable.html" title="BArchivable"><code class="classname">BArchivable</code></a></td></tr><tr><td>Declared In:</td><td><code class="filename">net/NetAddress.h</code></td></tr><tr><td>Library:</td><td><code class="filename">libnetapi.so</code></td></tr><tr><td>Allocation:</td><td>Constructor only</td></tr></tbody></table></td><td>
<a class="link overview" href="BNetAddress_Overview.html" title="BNetAddress">Class Overview</a>
<div class="toc"><ul><li><span class="section"><a href="BNetAddress.html#BNetAddress_ConstructorDestructor">Constructor and Destructor</a></span></li><li><span class="section"><a href="BNetAddress.html#BNetAddress_MemberFunctions">Member Functions</a></span></li></ul></div>
</td></tr></tbody></table></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><hr /><div xmlns:d="http://docbook.org/ns/docbook"><h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BNetAddress_ConstructorDestructor"></a>Constructor and Destructor</h3></div></div></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BNetAddress_Constructor"></a>BNetAddress()</h4></div></div></div><div class="synopsisgroup">
<code class="constructorsynopsis cpp"><span class="methodname">BNetAddress</span>(<span class="methodparam"><span class="modifier">const </span><span class="type">char* </span><span class="parameter">hostname</span><span class="initializer"> = <span class="constant">NULL</span></span></span>,<br />            <span class="methodparam"><span class="type">unsigned short </span><span class="parameter">port</span><span class="initializer"> = 0</span></span>);</code>
<code class="constructorsynopsis cpp"><span class="methodname">BNetAddress</span>(<span class="methodparam"><span class="modifier">const </span><span class="type">struct sockaddr_in&amp; </span><span class="parameter">sa</span></span>);</code>
<code class="constructorsynopsis cpp"><span class="methodname">BNetAddress</span>(<span class="methodparam"><span class="type">in_addr </span><span class="parameter">addr</span></span>,<br />            <span class="methodparam"><span class="type">int </span><span class="parameter">port</span><span class="initializer"> = 0</span></span>);</code>
<code class="constructorsynopsis cpp"><span class="methodname">BNetAddress</span>(<span class="methodparam"><span class="type">uint32 </span><span class="parameter">addr</span></span>,<br />            <span class="methodparam"><span class="type">int </span><span class="parameter">port</span><span class="initializer"> = 0</span></span>);</code>
<code class="constructorsynopsis cpp"><span class="methodname">BNetAddress</span>(<span class="methodparam"><span class="modifier">const </span><span class="type">char* </span><span class="parameter">hostname</span></span>,<br />            <span class="methodparam"><span class="modifier">const </span><span class="type">char* </span><span class="parameter">protocol</span></span>,<br />            <span class="methodparam"><span class="modifier">const </span><span class="type">char* </span><span class="parameter">service</span></span>);</code>
<code class="constructorsynopsis cpp"><span class="methodname">BNetAddress</span>(<span class="methodparam"><span class="type"><span class="classname">BNetAddress</span>&amp; </span><span class="parameter">from</span></span>);</code>
<code class="constructorsynopsis cpp"><span class="methodname">BNetAddress</span>(<span class="methodparam"><span class="type"><a class="link" href="BMessage.html" title="BMessage"><code class="classname">BMessage</code></a>* </span><span class="parameter">archive</span></span>);</code>
</div><p>Sets up the <code class="classname">BNetAddress</code> object to refer to the specified address. The
address can be specified in a number of ways:</p><ul class="itemizedlist"><li><p>By <code class="parameter">hostname</code> and
<code class="parameter">port</code> number. For example, to connect to the
<acronym class="acronym" title="HyperText Transport Protocol">HTTP</acronym>
port at www.be.com, you would specify "www.be.com" as the
<code class="parameter">hostname</code>, and 80 for the
<code class="parameter">port</code> number.</p></li><li><p>By <span class="type">sockaddr_in</span> structure. This structure contains the network family,
port number, and <acronym class="acronym" title="Internet Protocol">IP</acronym>
address that make up the address.</p></li><li><p>By <acronym class="acronym">IP</acronym> address and port number. The IP address can be specified either
using an <span class="type">in_addr</span>, or by using a <span class="type">uint32</span>. The <acronym class="acronym">IP</acronym> address must be
specified in network byte order. See the <code class="function">htonl()</code> function.</p></li><li><p>By <code class="parameter">hostname</code>,
<code class="parameter">protocol</code>, and <code class="parameter">service</code>
name. This causes the port to be looked up in the
<code class="filename">/etc/services</code> file by matching the protocol
(typically "tcp" or "udp") and service name (such as
"http" or "ftp") against the entries in the file. See
<code class="function">getservbyname()</code> for details on the format of this
file.</p></li><li><p>By copying an existing <code class="classname">BNetAddress</code>.</p></li><li><p>By unflattening an archived <code class="classname">BNetAddress</code>
from a
<a class="link" href="BMessage.html" title="BMessage"><code class="classname">BMessage</code></a>.</p></li></ul><p>After creating your <code class="classname">BNetAddress</code>, you must call
<a class="link" href="BNetAddress.html#BNetAddress_InitCheck" title="InitCheck()"><code class="methodname">InitCheck()</code></a>
to ensure that no errors occurred during setup. You can change the address later by
calling
<a class="link" href="BNetAddress.html#BNetAddress_SetTo" title="SetTo()"><code class="methodname">SetTo()</code></a>.</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BNetAddress_Destructor"></a>~BNetAddress()</h4></div></div></div><code class="destructorsynopsis cpp"><span class="modifier">virtual </span><span class="methodname">~BNetAddress</span>();</code><p>A typical destructor.</p></div></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><hr /><div xmlns:d="http://docbook.org/ns/docbook"><h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BNetAddress_MemberFunctions"></a>Member Functions</h3></div></div></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BNetAddress_InitCheck"></a>InitCheck()</h4></div></div></div><code class="methodsynopsis cpp"><span class="type">status_t </span><span class="methodname">InitCheck</span>() <span class="modifier">const</span>;</code><p>Returns a <span class="type">status_t</span> indicating whether or not the object was successfully
instantiated.</p><table class="variablelist returncodes"><thead><tr><th>Return Code</th><th>Description</th></tr></thead><tbody><tr><td><p><span class="term"><code class="constant">B_OK</code></span></p></td><td><p>The <code class="classname">BNetAddress</code> was constructed without error.</p></td></tr><tr><td><p><span class="term"><code class="constant">B_ERROR</code></span></p></td><td><p>An error occurred during construction.</p></td></tr></tbody></table></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BNetAddress_GetAddr"></a>GetAddr()</h4></div></div></div><div class="synopsisgroup">
<code class="methodsynopsis cpp"><span class="type">status_t </span><span class="methodname">GetAddr</span>(<span class="methodparam"><span class="modifier">const </span><span class="type">char* </span><span class="parameter">hostname</span><span class="initializer"> = <span class="constant">NULL</span></span></span>,<br />                 <span class="methodparam"><span class="type">unsigned short* </span><span class="parameter">port</span><span class="initializer"> = <span class="constant">NULL</span></span></span>) <span class="modifier">const</span>;</code>
<code class="methodsynopsis cpp"><span class="type">status_t </span><span class="methodname">GetAddr</span>(<span class="methodparam"><span class="modifier">const </span><span class="type">struct sockaddr_in&amp; </span><span class="parameter">sa</span></span>) <span class="modifier">const</span>;</code>
<code class="methodsynopsis cpp"><span class="type">status_t </span><span class="methodname">GetAddr</span>(<span class="methodparam"><span class="type">in_addr&amp; </span><span class="parameter">addr</span></span>,<br />                 <span class="methodparam"><span class="type">unsigned short* </span><span class="parameter">port</span><span class="initializer"> = <span class="constant">NULL</span></span></span>) <span class="modifier">const</span>;</code>
</div><p>Returns the address represented by the <code class="classname">BNetAddress</code>
object in the format indicated by the form of the function used.</p><p>If you don't care about the hostname (in the first form), you can specify
<code class="constant">NULL</code> for the <code class="parameter">hostname</code> argument;
if you don't care about the port number, you can specify
<code class="constant">NULL</code> for the <code class="parameter">port</code> argument.</p><table class="variablelist returncodes"><thead><tr><th>Return Code</th><th>Description</th></tr></thead><tbody><tr><td><p><span class="term"><code class="constant">B_OK</code></span></p></td><td><p>The address was returned successfully.</p></td></tr><tr><td><p><span class="term"><code class="constant">B_ERROR</code></span></p></td><td><p>An error occurred fetching the address information.</p></td></tr></tbody></table></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BNetAddress_SetTo"></a>SetTo()</h4></div></div></div><div class="synopsisgroup">
<code class="methodsynopsis cpp"><span class="type">status_t </span><span class="methodname">SetTo</span>(<span class="methodparam"><span class="modifier">const </span><span class="type">char* </span><span class="parameter">hostname</span></span>,<br />               <span class="methodparam"><span class="modifier">const </span><span class="type">char* </span><span class="parameter">protocol</span></span>,<br />               <span class="methodparam"><span class="modifier">const </span><span class="type">char* </span><span class="parameter">service</span></span>);</code>
<code class="methodsynopsis cpp"><span class="type">status_t </span><span class="methodname">SetTo</span>(<span class="methodparam"><span class="modifier">const </span><span class="type">char* </span><span class="parameter">hostname</span><span class="initializer"> = <span class="constant">NULL</span></span></span>,<br />               <span class="methodparam"><span class="type">unsigned short </span><span class="parameter">port</span><span class="initializer"> = 0</span></span>);</code>
<code class="methodsynopsis cpp"><span class="type">status_t </span><span class="methodname">SetTo</span>(<span class="methodparam"><span class="modifier">const </span><span class="type">struct sockaddr_in&amp; </span><span class="parameter">sa</span></span>);</code>
<code class="methodsynopsis cpp"><span class="type">status_t </span><span class="methodname">SetTo</span>(<span class="methodparam"><span class="type">in_addr </span><span class="parameter">addr</span></span>,<br />               <span class="methodparam"><span class="type">int </span><span class="parameter">port</span><span class="initializer"> = 0</span></span>);</code>
<code class="methodsynopsis cpp"><span class="type">status_t </span><span class="methodname">SetTo</span>(<span class="methodparam"><span class="type">uint32 </span><span class="parameter">addr</span><span class="initializer"> = <span class="constant">INADDR_ANY</span></span></span>,<br />               <span class="methodparam"><span class="type">int </span><span class="parameter">port</span><span class="initializer"> = 0</span></span>);</code>
</div><p>Sets the address represented by the <code class="classname">BNetAddress</code> object in the format
indicated by the form of the function used. These formats are described
in the discussion of the constructor.</p><table class="variablelist returncodes"><thead><tr><th>Return Code</th><th>Description</th></tr></thead><tbody><tr><td><p><span class="term"><code class="constant">B_OK</code></span></p></td><td><p>The address was set successfully.</p></td></tr><tr><td><p><span class="term"><code class="constant">B_ERROR</code></span></p></td><td><p>An error occurred setting the address information.</p></td></tr></tbody></table></div></div></div><div id="footer"><hr /><div id="footerT">Prev: <a href="TheNetworkKit.html">The Network Kit</a>  Up: <a href="TheNetworkKit.html">The Network Kit</a>  Next: <a href="BNetBuffer.html">BNetBuffer</a> </div><div id="footerB"><div id="footerBL"><a href="TheNetworkKit.html" title="The Network Kit"><img src="./images/navigation/prev.png" alt="Prev" /></a> <a href="TheNetworkKit.html" title="The Network Kit"><img src="./images/navigation/up.png" alt="Up" /></a> <a href="BNetBuffer.html" title="BNetBuffer"><img src="./images/navigation/next.png" alt="Next" /></a></div><div id="footerBR"><div><a href="http://www.haiku-os.org"><img src="./images/People_24.png" alt="haiku-os.org" title="Visit The Haiku Website" /></a></div><div class="navighome" title="Home"><a accesskey="h" href="index.html"><img src="./images/navigation/home.png" alt="Home" /></a></div></div><div id="footerBC"><a href="http://www.access-company.com/home.html" title="ACCESS Co."><img alt="Access Company" src="./images/access_logo.png" /></a></div></div></div><div id="licenseFooter"><div id="licenseFooterBL"><a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/" title="Creative Commons License"><img alt="Creative Commons License" style="border-width:0" src="https://licensebuttons.net/l/by-nc-nd/3.0/88x31.png" /></a></div><div id="licenseFooterBR"><a href="./LegalNotice.html">Legal Notice</a></div><div id="licenseFooterBC"><span id="licenseText">This work is licensed under a
<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/">Creative
Commons Attribution-Non commercial-No Derivative Works 3.0 License</a>.</span></div></div></body></html>