.\" -*- 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. .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .\" .\" 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. .\" .\" SPDX-License-Identifier: BSD-4-Clause-UC .\" .\" 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 "3 Mayo 2023" "Páginas de manual de Linux 6.05.01" .SH NOMBRE bind \- enlaza un nombre a un conector (socket) .SH BIBLIOTECA Biblioteca Estándar C (\fIlibc\fP, \fI\-lc\fP) .SH SINOPSIS .nf \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 \[lq]assigning 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 para indicar el error. .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 ESTÁNDARES POSIX.1\-2008. .SH HISTORIAL .\" SVr4 documents an additional .\" .B ENOSR .\" general error condition, and .\" additional .\" .B EIO .\" and .\" .B EISDIR .\" UNIX-domain error conditions. POSIX.1\-2001, SVr4, 4.4BSD (\fBbind\fP() first appeared in 4.2BSD). .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 .\" SRC BEGIN (bind.c) .EX #include #include #include #include #include #include \& #define MY_SOCK_PATH "/somepath" #define LISTEN_BACKLOG 50 \& #define handle_error(msg) \e do { perror(msg); exit(EXIT_FAILURE); } while (0) \& int main(void) { int sfd, cfd; socklen_t peer_addr_size; struct sockaddr_un my_addr, peer_addr; \& sfd = socket(AF_UNIX, SOCK_STREAM, 0); if (sfd == \-1) handle_error("socket"); \& memset(&my_addr, 0, sizeof(my_addr)); 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)... */ \& if (close(sfd) == \-1) handle_error("close"); \& if (unlink(MY_SOCK_PATH) == \-1) handle_error("unlink"); } .EE .\" SRC END .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) .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 .