.\" -*- coding: UTF-8 -*- .\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu) .\" and Copyright 2005-2007, Michael Kerrisk .\" Portions extracted from /usr/include/sys/socket.h, which does not have .\" any authorship information in it. It is probably available under the GPL. .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\" .\" Other portions are from the 6.9 (Berkeley) 3/10/91 man page: .\" .\" Copyright (c) 1983 The Regents of the University of California. .\" All rights reserved. .\" .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB) .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" %%%LICENSE_END .\" .\" Modified Mon Oct 21 23:05:29 EDT 1996 by Eric S. Raymond .\" Modified 1998 by Andi Kleen .\" $Id: bind.2,v 1.3 1999/04/23 19:56:07 freitag Exp $ .\" Modified 2004-06-23 by Michael Kerrisk .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH BIND 2 "1 Noviembre 2020" Linux "Manual del Programador de Linux" .SH NOMBRE bind \- enlaza un nombre a un conector (socket) .SH SINOPSIS .nf \fB#include \fP /* Vea NOTAS */ \fB#include \fP .PP \fBint bind(int \fP\fIsockfd\fP\fB, const struct sockaddr *\fP\fIaddr\fP\fB,\fP \fB socklen_t \fP\fIaddrlen\fP\fB);\fP .fi .SH DESCRIPCIÓN When a socket is created with \fBsocket\fP(2), it exists in a name space (address family) but has no address assigned to it. \fBbind\fP() assigns the address specified by \fIaddr\fP to the socket referred to by the file descriptor \fIsockfd\fP. \fIaddrlen\fP specifies the size, in bytes, of the address structure pointed to by \fIaddr\fP. Traditionally, this operation is called \(lqassigning a name to a socket\(rq. .PP Normalmente, es necesario asignar una dirección local usando \fBbind\fP() a un conector \fBSOCK_STREAM\fP antes de que éste pueda recibir conexiones (vea \fBaccept\fP(2)). .PP Las reglas usadas en el enlace de nombres varían entre familias de direcciones. Consulte las entradas de manual de la Sección 7 para obtener una información más detallada. Para \fBAF_INET\fP vea \fBip\fP(7), para \fBAF_INET6\fP vea \fBipv6\fP(7), para \fBAF_UNIX\fP vea \fBunix\fP(7), para \fBAF_APPLETALK\fP vea \fBddp\fP(7), para \fBAF_PACKET\fP vea \fBpacket\fP(7), para \fBAF_X25\fP vea \fBx25\fP(7) y para \fBAF_NETLINK\fP vea \fBnetlink\fP(7). .PP The actual structure passed for the \fIaddr\fP argument will depend on the address family. The \fIsockaddr\fP structure is defined as something like: .PP .in +4n .EX struct sockaddr { sa_family_t sa_family; char sa_data[14]; } .EE .in .PP The only purpose of this structure is to cast the structure pointer passed in \fIaddr\fP in order to avoid compiler warnings. See EXAMPLES below. .SH "VALOR DEVUELTO" En caso de éxito se devuelve cero. En caso de error se devuelve \-1, y \fIerrno\fP se configura adecuadamente. .SH ERRORES .TP \fBEACCES\fP .\" e.g., privileged port in AF_INET domain La dirección está protegida y el usuario no es el superusuario. .TP \fBEADDRINUSE\fP The given address is already in use. .TP \fBEADDRINUSE\fP (Internet domain sockets) The port number was specified as zero in the socket address structure, but, upon attempting to bind to an ephemeral port, it was determined that all port numbers in the ephemeral port range are currently in use. See the discussion of \fI/proc/sys/net/ipv4/ip_local_port_range\fP \fBip\fP(7). .TP \fBEBADF\fP \fIsockfd\fP no es un descriptor de archivo válido. .TP \fBEINVAL\fP .\" This may change in the future: see .\" .I linux/unix/sock.c for details. The socket is already bound to an address. .TP \fBEINVAL\fP \fIaddrlen\fP is wrong, or \fIaddr\fP is not a valid address for this socket's domain. .TP \fBENOTSOCK\fP El descriptor de archivo \fIsockfd\fP no se refiere a un conector. .PP Los siguientes errores son específicos a los conectores del dominio UNIX (\fIAF_UNIX\fP): .TP \fBEACCES\fP El permiso de búsqueda ha sido denegado en uno de los componentes de la ruta. Consulte \fBpath_resolution\fP(7). .TP \fBEADDRNOTAVAIL\fP Se requirió una interfaz inexistente o una dirección no local. .TP \fBEFAULT\fP \fIaddr\fP señala fuera del espacio de direcciones accesible por el usuario. .TP \fBELOOP\fP Se han encontrado demasiados enlaces simbólicos al resolver \fIaddr\fP. .TP \fBENAMETOOLONG\fP \fIaddr\fP es demasiado larga. .TP \fBENOENT\fP No existe algún componente del prefijo del directorio del nombre de ruta del conector. .TP \fBENOMEM\fP No hay disponible suficiente memoria del núcleo. .TP \fBENOTDIR\fP Un componente del prefijo de la ruta no es un directorio. .TP \fBEROFS\fP El nodo\-i del conector reside en un sistema de ficheros de `sólo lectura'. .SH "CONFORME A" .\" SVr4 documents an additional .\" .B ENOSR .\" general error condition, and .\" additional .\" .B EIO .\" and .\" .B EISDIR .\" UNIX-domain error conditions. POSIX.1\-2001, POSIX.1\-2008, SVr4, 4.4BSD (\fBbind\fP() por primera vez en 4.2BSD). .SH NOTAS POSIX.1 does not require the inclusion of \fI\fP, and this header file is not required on Linux. However, some historical (BSD) implementations required this header file, and portable applications are probably wise to include it. .PP Para saber más acerca del tipo \fIsocklen_t\fP, consulte \fBaccept\fP(2). .SH ERRORES .\" FIXME Document transparent proxy options No están descritas las opciones de proxy transparente. .SH EJEMPLOS An example of the use of \fBbind\fP() with Internet domain sockets can be found in \fBgetaddrinfo\fP(3). .PP .\" listen.7 refers to this example. .\" accept.7 refers to this example. .\" unix.7 refers to this example. The following example shows how to bind a stream socket in the UNIX (\fBAF_UNIX\fP) domain, and accept connections: .PP .EX #include #include #include #include #include #define MY_SOCK_PATH "/unaruta" #define LISTEN_BACKLOG 50 #define handle_error(msg) \e do { perror(msg); exit(EXIT_FAILURE); } while (0) int main(int argc, char *argv[]) { int sfd, cfd; struct sockaddr_un my_addr, peer_addr; socklen_t peer_addr_size; sfd = socket(AF_UNIX, SOCK_STREAM, 0); if (sfd == \-1) handle_error("socket"); memset(&my_addr, 0, sizeof(my_addr)); /* Clear structure */ my_addr.sun_family = AF_UNIX; strncpy(my_addr.sun_path, MY_SOCK_PATH, sizeof(my_addr.sun_path) \- 1); if (bind(sfd, (struct sockaddr *) &my_addr, sizeof(my_addr)) == \-1) handle_error("bind"); if (listen(sfd, LISTEN_BACKLOG) == \-1) handle_error("listen"); /* Now we can accept incoming connections one at a time using accept(2) */ peer_addr_size = sizeof(peer_addr); cfd = accept(sfd, (struct sockaddr *) &peer_addr, &peer_addr_size); if (cfd == \-1) handle_error("accept"); /* Code to deal with incoming connection(s)... */ /* When no longer required, the socket pathname, MY_SOCK_PATH should be deleted using unlink(2) or remove(3) */ } .EE .SH "VÉASE TAMBIÉN" \fBaccept\fP(2), \fBconnect\fP(2), \fBgetsockname\fP(2), \fBlisten\fP(2), \fBsocket\fP(2), \fBgetaddrinfo\fP(3), \fBgetifaddrs\fP(3), \fBip\fP(7), \fBipv6\fP(7), \fBpath_resolution\fP(7), \fBsocket\fP(7), \fBunix\fP(7) .SH COLOFÓN Esta página es parte de la versión 5.10 del proyecto Linux \fIman\-pages\fP. Puede encontrar una descripción del proyecto, información sobre cómo informar errores y la última versión de esta página en \%https://www.kernel.org/doc/man\-pages/. .PP .SH TRADUCCIÓN La traducción al español de esta página del manual fue creada por Miguel Angel Sepulveda , Juan Piernas y Marcos Fouces . .PP Esta traducción es documentación libre; lea la .UR https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 .UE o posterior con respecto a las condiciones de copyright. No existe NINGUNA RESPONSABILIDAD. .PP Si encuentra algún error en la traducción de esta página del manual, envíe un correo electrónico a .MT debian-l10n-spanish@lists.debian.org .ME .