| <html lang="en"> |
| <head> |
| <title>Address Formats - The GNU C Library</title> |
| <meta http-equiv="Content-Type" content="text/html"> |
| <meta name="description" content="The GNU C Library"> |
| <meta name="generator" content="makeinfo 4.13"> |
| <link title="Top" rel="start" href="index.html#Top"> |
| <link rel="up" href="Socket-Addresses.html#Socket-Addresses" title="Socket Addresses"> |
| <link rel="next" href="Setting-Address.html#Setting-Address" title="Setting Address"> |
| <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> |
| <!-- |
| This file documents the GNU C library. |
| |
| This is Edition 0.12, last updated 2007-10-27, |
| of `The GNU C Library Reference Manual', for version |
| 2.8 (Sourcery G++ Lite 2011.03-41). |
| |
| Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002, |
| 2003, 2007, 2008, 2010 Free Software Foundation, Inc. |
| |
| 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 the |
| Invariant Sections being ``Free Software Needs Free Documentation'' |
| and ``GNU Lesser General Public License'', the Front-Cover texts being |
| ``A GNU Manual'', and with the Back-Cover Texts as in (a) below. A |
| copy of the license is included in the section entitled "GNU Free |
| Documentation License". |
| |
| (a) The FSF's Back-Cover Text is: ``You have the freedom to |
| copy and modify this GNU manual. Buying copies from the FSF |
| supports it in developing GNU and promoting software freedom.''--> |
| <meta http-equiv="Content-Style-Type" content="text/css"> |
| <style type="text/css"><!-- |
| pre.display { font-family:inherit } |
| pre.format { font-family:inherit } |
| pre.smalldisplay { font-family:inherit; font-size:smaller } |
| pre.smallformat { font-family:inherit; font-size:smaller } |
| pre.smallexample { font-size:smaller } |
| pre.smalllisp { font-size:smaller } |
| span.sc { font-variant:small-caps } |
| span.roman { font-family:serif; font-weight:normal; } |
| span.sansserif { font-family:sans-serif; font-weight:normal; } |
| --></style> |
| <link rel="stylesheet" type="text/css" href="../cs.css"> |
| </head> |
| <body> |
| <div class="node"> |
| <a name="Address-Formats"></a> |
| <p> |
| Next: <a rel="next" accesskey="n" href="Setting-Address.html#Setting-Address">Setting Address</a>, |
| Up: <a rel="up" accesskey="u" href="Socket-Addresses.html#Socket-Addresses">Socket Addresses</a> |
| <hr> |
| </div> |
| |
| <h4 class="subsection">16.3.1 Address Formats</h4> |
| |
| <p>The functions <code>bind</code> and <code>getsockname</code> use the generic data |
| type <code>struct sockaddr *</code> to represent a pointer to a socket |
| address. You can't use this data type effectively to interpret an |
| address or construct one; for that, you must use the proper data type |
| for the socket's namespace. |
| |
| <p>Thus, the usual practice is to construct an address of the proper |
| namespace-specific type, then cast a pointer to <code>struct sockaddr *</code> |
| when you call <code>bind</code> or <code>getsockname</code>. |
| |
| <p>The one piece of information that you can get from the <code>struct |
| sockaddr</code> data type is the <dfn>address format designator</dfn>. This tells |
| you which data type to use to understand the address fully. |
| |
| <p><a name="index-sys_002fsocket_002eh-1655"></a>The symbols in this section are defined in the header file |
| <samp><span class="file">sys/socket.h</span></samp>. |
| |
| <!-- sys/socket.h --> |
| <!-- BSD --> |
| <div class="defun"> |
| — Data Type: <b>struct sockaddr</b><var><a name="index-struct-sockaddr-1656"></a></var><br> |
| <blockquote><p>The <code>struct sockaddr</code> type itself has the following members: |
| |
| <dl> |
| <dt><code>short int sa_family</code><dd>This is the code for the address format of this address. It |
| identifies the format of the data which follows. |
| |
| <br><dt><code>char sa_data[14]</code><dd>This is the actual socket address data, which is format-dependent. Its |
| length also depends on the format, and may well be more than 14. The |
| length 14 of <code>sa_data</code> is essentially arbitrary. |
| </dl> |
| </p></blockquote></div> |
| |
| <p>Each address format has a symbolic name which starts with ‘<samp><span class="samp">AF_</span></samp>’. |
| Each of them corresponds to a ‘<samp><span class="samp">PF_</span></samp>’ symbol which designates the |
| corresponding namespace. Here is a list of address format names: |
| |
| <dl> |
| <!-- sys/socket.h --> |
| <!-- POSIX --> |
| <dt><code>AF_LOCAL</code><dd><a name="index-AF_005fLOCAL-1657"></a>This designates the address format that goes with the local namespace. |
| (<code>PF_LOCAL</code> is the name of that namespace.) See <a href="Local-Namespace-Details.html#Local-Namespace-Details">Local Namespace Details</a>, for information about this address format. |
| |
| <!-- sys/socket.h --> |
| <!-- BSD, Unix98 --> |
| <br><dt><code>AF_UNIX</code><dd><a name="index-AF_005fUNIX-1658"></a>This is a synonym for <code>AF_LOCAL</code>. Although <code>AF_LOCAL</code> is |
| mandated by POSIX.1g, <code>AF_UNIX</code> is portable to more systems. |
| <code>AF_UNIX</code> was the traditional name stemming from BSD, so even most |
| POSIX systems support it. It is also the name of choice in the Unix98 |
| specification. (The same is true for <code>PF_UNIX</code> |
| vs. <code>PF_LOCAL</code>). |
| |
| <!-- sys/socket.h --> |
| <!-- GNU --> |
| <br><dt><code>AF_FILE</code><dd><a name="index-AF_005fFILE-1659"></a>This is another synonym for <code>AF_LOCAL</code>, for compatibility. |
| (<code>PF_FILE</code> is likewise a synonym for <code>PF_LOCAL</code>.) |
| |
| <!-- sys/socket.h --> |
| <!-- BSD --> |
| <br><dt><code>AF_INET</code><dd><a name="index-AF_005fINET-1660"></a>This designates the address format that goes with the Internet |
| namespace. (<code>PF_INET</code> is the name of that namespace.) |
| See <a href="Internet-Address-Formats.html#Internet-Address-Formats">Internet Address Formats</a>. |
| |
| <!-- sys/socket.h --> |
| <!-- IPv6 Basic API --> |
| <br><dt><code>AF_INET6</code><dd>This is similar to <code>AF_INET</code>, but refers to the IPv6 protocol. |
| (<code>PF_INET6</code> is the name of the corresponding namespace.) |
| |
| <!-- sys/socket.h --> |
| <!-- BSD --> |
| <br><dt><code>AF_UNSPEC</code><dd><a name="index-AF_005fUNSPEC-1661"></a>This designates no particular address format. It is used only in rare |
| cases, such as to clear out the default destination address of a |
| “connected” datagram socket. See <a href="Sending-Datagrams.html#Sending-Datagrams">Sending Datagrams</a>. |
| |
| <p>The corresponding namespace designator symbol <code>PF_UNSPEC</code> exists |
| for completeness, but there is no reason to use it in a program. |
| </dl> |
| |
| <p><samp><span class="file">sys/socket.h</span></samp> defines symbols starting with ‘<samp><span class="samp">AF_</span></samp>’ for many |
| different kinds of networks, most or all of which are not actually |
| implemented. We will document those that really work as we receive |
| information about how to use them. |
| |
| </body></html> |
| |