186 lines
13 KiB
HTML
186 lines
13 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<!-- This manual documents Guile version 3.0.10.
|
|
|
|
Copyright (C) 1996-1997, 2000-2005, 2009-2023 Free Software Foundation,
|
|
Inc.
|
|
|
|
Copyright (C) 2021 Maxime Devos
|
|
|
|
Copyright (C) 2024 Tomas Volf
|
|
|
|
|
|
Permission is granted to copy, distribute and/or modify this document
|
|
under the terms of the GNU Free Documentation License, Version 1.3 or
|
|
any later version published by the Free Software Foundation; with no
|
|
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
|
|
copy of the license is included in the section entitled "GNU Free
|
|
Documentation License." -->
|
|
<title>Network Socket Address (Guile Reference Manual)</title>
|
|
|
|
<meta name="description" content="Network Socket Address (Guile Reference Manual)">
|
|
<meta name="keywords" content="Network Socket Address (Guile Reference Manual)">
|
|
<meta name="resource-type" content="document">
|
|
<meta name="distribution" content="global">
|
|
<meta name="Generator" content=".texi2any-real">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
|
|
<link href="index.html" rel="start" title="Top">
|
|
<link href="Concept-Index.html" rel="index" title="Concept Index">
|
|
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
|
|
<link href="Networking.html" rel="up" title="Networking">
|
|
<link href="Network-Sockets-and-Communication.html" rel="next" title="Network Sockets and Communication">
|
|
<link href="Network-Databases.html" rel="prev" title="Network Databases">
|
|
<style type="text/css">
|
|
<!--
|
|
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
|
|
span:hover a.copiable-link {visibility: visible}
|
|
strong.def-name {font-family: monospace; font-weight: bold; font-size: larger}
|
|
-->
|
|
</style>
|
|
<link rel="stylesheet" type="text/css" href="https://www.gnu.org/software/gnulib/manual.css">
|
|
|
|
|
|
</head>
|
|
|
|
<body lang="en">
|
|
<div class="subsubsection-level-extent" id="Network-Socket-Address">
|
|
<div class="nav-panel">
|
|
<p>
|
|
Next: <a href="Network-Sockets-and-Communication.html" accesskey="n" rel="next">Network Sockets and Communication</a>, Previous: <a href="Network-Databases.html" accesskey="p" rel="prev">Network Databases</a>, Up: <a href="Networking.html" accesskey="u" rel="up">Networking</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
|
|
</div>
|
|
<hr>
|
|
<h4 class="subsubsection" id="Network-Socket-Address-1"><span>7.2.11.3 Network Socket Address<a class="copiable-link" href="#Network-Socket-Address-1"> ¶</a></span></h4>
|
|
<a class="index-entry-id" id="index-socket-address"></a>
|
|
<a class="index-entry-id" id="index-network-socket-address"></a>
|
|
<a class="index-entry-id" id="index-Socket-address"></a>
|
|
|
|
<p>A <em class="dfn">socket address</em> object identifies a socket endpoint for
|
|
communication. In the case of <code class="code">AF_INET</code> for instance, the socket
|
|
address object comprises the host address (or interface on the host)
|
|
and a port number which specifies a particular open socket in a
|
|
running client or server process. A socket address object can be
|
|
created with,
|
|
</p>
|
|
<dl class="first-deffn">
|
|
<dt class="deffn" id="index-make_002dsocket_002daddress"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">make-socket-address</strong> <var class="def-var-arguments">AF_INET ipv4addr port</var><a class="copiable-link" href="#index-make_002dsocket_002daddress"> ¶</a></span></dt>
|
|
<dt class="deffnx def-cmd-deffn" id="index-make_002dsocket_002daddress-1"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">make-socket-address</strong> <var class="def-var-arguments">AF_INET6 ipv6addr port [flowinfo [scopeid]]</var><a class="copiable-link" href="#index-make_002dsocket_002daddress-1"> ¶</a></span></dt>
|
|
<dt class="deffnx def-cmd-deffn" id="index-make_002dsocket_002daddress-2"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">make-socket-address</strong> <var class="def-var-arguments">AF_UNIX path</var><a class="copiable-link" href="#index-make_002dsocket_002daddress-2"> ¶</a></span></dt>
|
|
<dt class="deffnx def-cmd-deffn" id="index-scm_005fmake_005fsocket_005faddress"><span class="category-def">C Function: </span><span><strong class="def-name">scm_make_socket_address</strong> <var class="def-var-arguments">(family, address, arglist)</var><a class="copiable-link" href="#index-scm_005fmake_005fsocket_005faddress"> ¶</a></span></dt>
|
|
<dd><p>Return a new socket address object. The first argument is the address
|
|
family, one of the <code class="code">AF</code> constants, then the arguments vary
|
|
according to the family.
|
|
</p>
|
|
<p>For <code class="code">AF_INET</code> the arguments are an IPv4 network address number
|
|
(see <a class="pxref" href="Network-Address-Conversion.html">Network Address Conversion</a>), and a port number.
|
|
</p>
|
|
<p>For <code class="code">AF_INET6</code> the arguments are an IPv6 network address number
|
|
and a port number. Optional <var class="var">flowinfo</var> and <var class="var">scopeid</var>
|
|
arguments may be given (both integers, default 0).
|
|
</p>
|
|
<p>For <code class="code">AF_UNIX</code> the argument is a filename (a string).
|
|
</p>
|
|
<p>The C function <code class="code">scm_make_socket_address</code> takes the <var class="var">family</var>
|
|
and <var class="var">address</var> arguments directly, then <var class="var">arglist</var> is a list of
|
|
further arguments, being the port for IPv4, port and optional flowinfo
|
|
and scopeid for IPv6, or the empty list <code class="code">SCM_EOL</code> for Unix
|
|
domain.
|
|
</p></dd></dl>
|
|
|
|
<p>The following functions access the fields of a socket address object,
|
|
</p>
|
|
<dl class="first-deffn">
|
|
<dt class="deffn" id="index-sockaddr_003afam"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">sockaddr:fam</strong> <var class="def-var-arguments">sa</var><a class="copiable-link" href="#index-sockaddr_003afam"> ¶</a></span></dt>
|
|
<dd><p>Return the address family from socket address object <var class="var">sa</var>. This
|
|
is one of the <code class="code">AF</code> constants (e.g. <code class="code">AF_INET</code>).
|
|
</p></dd></dl>
|
|
|
|
<dl class="first-deffn">
|
|
<dt class="deffn" id="index-sockaddr_003apath"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">sockaddr:path</strong> <var class="def-var-arguments">sa</var><a class="copiable-link" href="#index-sockaddr_003apath"> ¶</a></span></dt>
|
|
<dd><p>For an <code class="code">AF_UNIX</code> socket address object <var class="var">sa</var>, return the
|
|
filename.
|
|
</p></dd></dl>
|
|
|
|
<dl class="first-deffn">
|
|
<dt class="deffn" id="index-sockaddr_003aaddr"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">sockaddr:addr</strong> <var class="def-var-arguments">sa</var><a class="copiable-link" href="#index-sockaddr_003aaddr"> ¶</a></span></dt>
|
|
<dd><p>For an <code class="code">AF_INET</code> or <code class="code">AF_INET6</code> socket address object
|
|
<var class="var">sa</var>, return the network address number.
|
|
</p></dd></dl>
|
|
|
|
<dl class="first-deffn">
|
|
<dt class="deffn" id="index-sockaddr_003aport"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">sockaddr:port</strong> <var class="def-var-arguments">sa</var><a class="copiable-link" href="#index-sockaddr_003aport"> ¶</a></span></dt>
|
|
<dd><p>For an <code class="code">AF_INET</code> or <code class="code">AF_INET6</code> socket address object
|
|
<var class="var">sa</var>, return the port number.
|
|
</p></dd></dl>
|
|
|
|
<dl class="first-deffn">
|
|
<dt class="deffn" id="index-sockaddr_003aflowinfo"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">sockaddr:flowinfo</strong> <var class="def-var-arguments">sa</var><a class="copiable-link" href="#index-sockaddr_003aflowinfo"> ¶</a></span></dt>
|
|
<dd><p>For an <code class="code">AF_INET6</code> socket address object <var class="var">sa</var>, return the
|
|
flowinfo value.
|
|
</p></dd></dl>
|
|
|
|
<dl class="first-deffn">
|
|
<dt class="deffn" id="index-sockaddr_003ascopeid"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">sockaddr:scopeid</strong> <var class="def-var-arguments">sa</var><a class="copiable-link" href="#index-sockaddr_003ascopeid"> ¶</a></span></dt>
|
|
<dd><p>For an <code class="code">AF_INET6</code> socket address object <var class="var">sa</var>, return the
|
|
scope ID value.
|
|
</p></dd></dl>
|
|
|
|
<a class="index-entry-id" id="index-struct-sockaddr"></a>
|
|
<a class="index-entry-id" id="index-sockaddr"></a>
|
|
<p>The functions below convert to and from the C <code class="code">struct sockaddr</code>
|
|
(see <a data-manual="libc" href="https://www.gnu.org/software/libc/manual/html_node/Address-Formats.html#Address-Formats">Address Formats</a> in <cite class="cite">The GNU C Library Reference Manual</cite>).
|
|
That structure is a generic type, an application can cast to or from
|
|
<code class="code">struct sockaddr_in</code>, <code class="code">struct sockaddr_in6</code> or <code class="code">struct
|
|
sockaddr_un</code> according to the address family.
|
|
</p>
|
|
<p>In a <code class="code">struct sockaddr</code> taken or returned, the byte ordering in
|
|
the fields follows the C conventions (see <a data-manual="libc" href="https://www.gnu.org/software/libc/manual/html_node/Byte-Order.html#Byte-Order">Byte Order
|
|
Conversion</a> in <cite class="cite">The GNU C Library Reference Manual</cite>). This means
|
|
network byte order for <code class="code">AF_INET</code> host address
|
|
(<code class="code">sin_addr.s_addr</code>) and port number (<code class="code">sin_port</code>), and
|
|
<code class="code">AF_INET6</code> port number (<code class="code">sin6_port</code>). But at the Scheme
|
|
level these values are taken or returned in host byte order, so the
|
|
port is an ordinary integer, and the host address likewise is an
|
|
ordinary integer (as described in <a class="ref" href="Network-Address-Conversion.html">Network Address Conversion</a>).
|
|
</p>
|
|
<dl class="first-deftypefn">
|
|
<dt class="deftypefn" id="index-scm_005fc_005fmake_005fsocket_005faddress"><span class="category-def">C Function: </span><span><code class="def-type">struct sockaddr *</code> <strong class="def-name">scm_c_make_socket_address</strong> <code class="def-code-arguments">(SCM family, SCM address, SCM args, size_t *outsize)</code><a class="copiable-link" href="#index-scm_005fc_005fmake_005fsocket_005faddress"> ¶</a></span></dt>
|
|
<dd><p>Return a newly-<code class="code">malloc</code>ed <code class="code">struct sockaddr</code> created from
|
|
arguments like those taken by <code class="code">scm_make_socket_address</code> above.
|
|
</p>
|
|
<p>The size (in bytes) of the <code class="code">struct sockaddr</code> return is stored
|
|
into <code class="code">*<var class="var">outsize</var></code>. An application must call <code class="code">free</code> to
|
|
release the returned structure when no longer required.
|
|
</p></dd></dl>
|
|
|
|
<dl class="first-deftypefn">
|
|
<dt class="deftypefn" id="index-scm_005ffrom_005fsockaddr"><span class="category-def">C Function: </span><span><code class="def-type">SCM</code> <strong class="def-name">scm_from_sockaddr</strong> <code class="def-code-arguments">(const struct sockaddr *address, unsigned address_size)</code><a class="copiable-link" href="#index-scm_005ffrom_005fsockaddr"> ¶</a></span></dt>
|
|
<dd><p>Return a Scheme socket address object from the C <var class="var">address</var>
|
|
structure. <var class="var">address_size</var> is the size in bytes of <var class="var">address</var>.
|
|
</p></dd></dl>
|
|
|
|
<dl class="first-deftypefn">
|
|
<dt class="deftypefn" id="index-scm_005fto_005fsockaddr"><span class="category-def">C Function: </span><span><code class="def-type">struct sockaddr *</code> <strong class="def-name">scm_to_sockaddr</strong> <code class="def-code-arguments">(SCM address, size_t *address_size)</code><a class="copiable-link" href="#index-scm_005fto_005fsockaddr"> ¶</a></span></dt>
|
|
<dd><p>Return a newly-<code class="code">malloc</code>ed <code class="code">struct sockaddr</code> from a Scheme
|
|
level socket address object.
|
|
</p>
|
|
<p>The size (in bytes) of the <code class="code">struct sockaddr</code> return is stored
|
|
into <code class="code">*<var class="var">outsize</var></code>. An application must call <code class="code">free</code> to
|
|
release the returned structure when no longer required.
|
|
</p></dd></dl>
|
|
|
|
|
|
</div>
|
|
<hr>
|
|
<div class="nav-panel">
|
|
<p>
|
|
Next: <a href="Network-Sockets-and-Communication.html">Network Sockets and Communication</a>, Previous: <a href="Network-Databases.html">Network Databases</a>, Up: <a href="Networking.html">Networking</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
|
|
</div>
|
|
|
|
|
|
|
|
</body>
|
|
</html>
|