.\" -*- coding: UTF-8 -*- .\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu) .\" 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 "6 mars 2019" Linux "Manuel du programmeur Linux" .SH NOM bind \- Fournir un nom à une socket .SH SYNOPSIS .nf \fB#include \fP /* Consultez NOTES */ \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 DESCRIPTION Quand une socket est créée avec l'appel système \fBsocket\fP(2), elle existe dans l'espace des noms (famille d'adresses) mais n'a pas d'adresse assignée. \fBbind\fP() affecte l'adresse indiquée dans \fIaddr\fP à la socket référencée par le descripteur de fichier \fIsockfd\fP. \fIaddrlen\fP indique la taille, en octets, de la structure d'adresse pointée par \fIaddr\fP. Traditionnellement cette opération est appelée «\ affectation d'un nom à une socket\ ». .PP Il est normalement nécessaire d'affecter une adresse locale avec \fBbind\fP() avant qu'une socket \fBSOCK_STREAM\fP puisse recevoir des connexions (consultez \fBaccept\fP(2)). .PP Les règles d'affectation de nom varient suivant les familles d'adresses. Consultez les pages de manuel de la section 7 pour de plus amples informations. Pour \fBAF_INET\fP consultez \fBip\fP(7), pour \fBAF_INET6\fP consultez \fBipv6\fP(7), pour \fBAF_UNIX\fP consultez \fBunix\fP(7), pour \fBAF_APPLETALK\fP consultez \fBddp\fP(7), pour \fBAF_PACKET\fP consultez \fBpacket\fP(7), pour \fBAF_X25\fP consultez \fBx25\fP(7) et pour \fBAF_NETLINK\fP consultez \fBnetlink\fP(7). .PP La structure réellement passée dans le paramètre \fIaddr\fP dépend du domaine de communication. La structure \fIsockaddr\fP est définie comme\ : .PP .in +4n .EX struct sockaddr { sa_family_t sa_family; char sa_data[14]; } .EE .in .PP Le seul objet de cette structure est de transtyper le pointeur passé dans \fIaddr\fP pour éviter les avertissements du compilateur. Voir l'exemple donné ci\(hydessous. .SH "VALEUR RENVOYÉE" En cas de succès, zéro est renvoyé. En cas d'erreur, \fB\-1\fP est renvoyé et \fIerrno\fP reçoit une valeur adéquate. .SH ERREURS .TP \fBEACCES\fP .\" e.g., privileged port in AF_INET domain L'adresse est protégée et l'utilisateur n'est pas le superutilisateur. .TP \fBEADDRINUSE\fP L'adresse est déjà utilisée. .TP \fBEADDRINUSE\fP (Socket Internet) le numéro de port a reçu la valeur zéro dans la structure d'adresse de socket, mais lors d'une tentative d'attachement à un port éphémère, aucun port n'était disponible dans l'intervalle des ports éphémères. Consultez les explications concernant \fI/proc/sys/net/ipv4/ip_local_port_range\fP dans \fBip\fP(7). .TP \fBEBADF\fP \fIsockfd\fP n'est pas un descripteur de fichier valable. .TP \fBEINVAL\fP .\" This may change in the future: see .\" .I linux/unix/sock.c for details. La socket est déjà connectée. .TP \fBEINVAL\fP \fIaddrlen\fP est faux ou \fIaddr\fP n'est pas une adresse valide pour le domaine de cette socket. .TP \fBENOTSOCK\fP Le descripteur de fichier \fIsockfd\fP ne fait pas référence à un socket. .PP Les erreurs suivantes sont spécifiques aux sockets du domaine UNIX (\fBAF_UNIX\fP)\ : .TP \fBEACCES\fP L'accès à un élément du chemin est interdit. (Voir aussi \fBpath_resolution\fP(7).) .TP \fBEADDRNOTAVAIL\fP Une interface inexistante est demandée, ou bien l'adresse demandée n'est pas locale. .TP \fBEFAULT\fP \fIaddr\fP pointe en dehors de l'espace d'adresse accessible. .TP \fBELOOP\fP \fIaddr\fP contient des références circulaires (à travers un lien symbolique). .TP \fBENAMETOOLONG\fP \fIaddr\fP est trop long. .TP \fBENOENT\fP Un composant du préfixe du répertoire du chemin de la socket n'existe pas. .TP \fBENOMEM\fP La mémoire disponible du noyau n'était pas suffisante. .TP \fBENOTDIR\fP Un élément du chemin d'accès n'est pas un répertoire. .TP \fBEROFS\fP L'inœud se trouverait dans un système de fichiers en lecture seule. .SH CONFORMITÉ .\" 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() est apparu dans BSD\ 4.2). .SH NOTES POSIX.1\-2001 ne requiert pas l'inclusion de \fI\fP, et cet en\(hytête n'est pas nécessaire sous Linux. Cependant, il doit être inclus sous certaines implémentations historiques (BSD), et les applications portables devraient probablement l'utiliser. .PP Pour plus de détails sur le type \fIsocklen_t\fP, voir \fBaccept\fP(2). .SH BOGUES .\" FIXME Document transparent proxy options Les options de proxy transparent ne sont pas décrites. .SH EXEMPLE Un exemple d'utilisation de \fBbind\fP() avec des sockets Internet se trouve dans \fBgetaddrinfo\fP(3). .PP .\" listen.7 refers to this example. .\" accept.7 refers to this example. .\" unix.7 refers to this example. L'exemple suivant montre comment affecter un nom à une socket du domaine UNIX (\fBAF_UNIX\fP), et accepter les connexions\ : .PP .EX #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(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(struct sockaddr_un)); /* Efface la 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(struct sockaddr_un)) == \-1) handle_error("bind"); if (listen(sfd, LISTEN_BACKLOG) == \-1) handle_error("listen"); /* Nous pouvons maintenant accepter une connexion entrante à la fois grâce à accept(2) */ peer_addr_size = sizeof(struct sockaddr_un); cfd = accept(sfd, (struct sockaddr *) &peer_addr, &peer_addr_size); if (cfd == \-1) handle_error("accept"); /* Code gérant les connexions entrantes... */ /* Lorsqu'il n'est plus nécessaire, le fichier de la socket, MY_SOCK_PATH, doit être supprimé avec unlink(2) ou remove(3) */ .EE .SH "VOIR AUSSI" \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 COLOPHON Cette page fait partie de la publication\ 5.04 du projet \fIman\-pages\fP Linux. Une description du projet et des instructions pour signaler des anomalies et la dernière version de cette page peuvent être trouvées à l'adresse \%https://www.kernel.org/doc/man\-pages/. .SH TRADUCTION La traduction française de cette page de manuel a été créée par Christophe Blaess , Stéphan Rafin , Thierry Vignaud , François Micaux, Alain Portal , Jean-Philippe Guérard , Jean-Luc Coulon (f5ibh) , Julien Cristau , Thomas Huriaux , Nicolas François , Florentin Duneau , Simon Paillard , Denis Barbier , David Prévot , Cédric Boutillier , Frédéric Hantrais et Jean-Philippe MENGUAL . Cette traduction est une documentation libre ; veuillez vous reporter à la .UR https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License version 3 .UE concernant les conditions de copie et de distribution. Il n'y a aucune RESPONSABILITÉ LÉGALE. Si vous découvrez un bogue dans la traduction de cette page de manuel, veuillez envoyer un message à .MT debian-l10n-french@lists.debian.org .ME .