.\" -*- 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 "12. Dezember 2016" Linux Linux\-Programmierhandbuch .SH BEZEICHNUNG bind \- verbindet einen Namen mit einem Socket .SH ÜBERSICHT .nf \fB#include \fP /* Siehe ANMERKUNGEN */ \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 BESCHREIBUNG Wenn ein Socket mit \fBsocket\fP(2) erstellt wird, existiert er in einem Namensraum (Adressfamilie), ihm wurde aber noch keine Adresse zugewiesen. \fBbind\fP() weist die von \fIaddr\fP angegebene Adresse dem Socket zu, auf den der Dateideskriptor \fIsockfd\fP weist. \fIaddrlen\fP gibt die Größe der durch \fIaddr\fP bestimmten Adress\-Struktur in Byte an. Traditionell wird diese Operation als »zuweisen eines Namens zu einem Socket« bezeichnet. .PP Es ist normalerweise notwendig, eine lokale Adresse mittels \fBbind\fP() zuzuweisen, bevor ein \fBSOCK_STREAM\fP\-Socket Verbindungen annehmen kann (siehe \fBaccept\fP(2)). .PP Die verwendeten Regeln für die Bindung/Zuweisung von Namen variieren zwischen den Adressfamilien. Ziehen Sie für detaillierte Informationen die Handbuch\-Einträge in Abschnitt 7 zu Rate. Für \fBAF_INET\fP siehe \fBip\fP(7), für \fBAF_INET6\fP siehe \fBipv6\fP(7), für \fBAF_UNIX\fP siehe \fBunix\fP(7), für \fBAF_APPLETALK\fP siehe \fBddp\fP(7), für \fBAF_PACKET\fP siehe \fBpacket\fP(7), für \fBAF_X25\fP siehe \fBx25\fP(7) und für \fBAF_NETLINK\fP siehe \fBnetlink\fP(7). .PP Die tatsächlich für das \fIaddr\fP\-Argument übergebene Struktur wird von der Adressfamilie abhängen. Die \fIsockaddr\fP\-Struktur ist ungefähr wie folgt definiert: .PP .in +4n .EX struct sockaddr { sa_family_t sa_family; char sa_data[14]; } .EE .in .PP Der einzige Zweck dieser Struktur ist die Typumwandlung des in \fIaddr\fP übergebenen Zeigers, um Compiler\-Warnungen zu vermeiden (siehe das folgende BEISPIEL). .SH RÜCKGABEWERT Bei Erfolg wird Null zurückgegeben. Bei einem Fehler wird \-1 zurückgegeben und \fIerrno\fP entsprechend gesetzt. .SH FEHLER .TP \fBEACCES\fP .\" e.g., privileged port in AF_INET domain Die Adresse ist geschützt und der Benutzer ist nicht der Super\-User. .TP \fBEADDRINUSE\fP Die angegebene Adresse wird schon verwendet. .TP \fBEADDRINUSE\fP (Internet\-Domain\-Sockets) Die Portnummer wurde in der Socket\-Adressstruktur als Null angegeben, aber beim Versuch, einen flüchtigen Port zu binden, wurde festgestellt, dass alle Portnummern im flüchtigen Port\-Bereich in Benutzung sind. Siehe die Erläuterungen zu \fI/proc/sys/net/ipv4/ip_local_port_range\fP \fBip\fP(7). .TP \fBEBADF\fP \fIsockfd\fP ist kein zulässiger Dateideskriptor. .TP \fBEINVAL\fP .\" This may change in the future: see .\" .I linux/unix/sock.c for details. Der Socket ist schon an eine Adresse gebunden. .TP \fBEINVAL\fP \fIaddrlen\fP ist falsch oder \fIaddr\fP ist keine gültige Adresse für die Domain des Sockets. .TP \fBENOTSOCK\fP Der Dateideskriptor \fIsockfd\fP zeigt nicht auf ein Socket. .PP Die folgenden Fehlermeldungen sind spezifisch für UNIX Domain Sockets (AF_UNIX): .TP \fBEACCES\fP Eine Komponente des Pfad\-Präfix darf nicht durchsucht werden. (Siehe auch \fBpath_resolution\fP(7).) .TP \fBEADDRNOTAVAIL\fP Es wurde eine nicht vorhandene Schnittstelle angefordert oder die Adresse war keine lokale Adresse. .TP \fBEFAULT\fP \fIaddr\fP zeigt aus dem vom Benutzer adressierbaren Adressraum heraus. .TP \fBELOOP\fP Bei der Auflösung von \fIaddr\fP wurden zu viele symbolische Verknüpfungen gefunden. .TP \fBENAMETOOLONG\fP \fIaddr\fP ist zu lang. .TP \fBENOENT\fP Eine Komponente in dem Verzeichnispräfix des Socket\-Pfadnames existiert nicht. .TP \fBENOMEM\fP Es war nicht genügend Kernelspeicher verfügbar. .TP \fBENOTDIR\fP Eine Komponente des Pfad\-Präfixes ist kein Verzeichnis. .TP \fBEROFS\fP Der Inode des Sockets würde sich auf einem nur lesbaren (read\-only) Dateisystem befinden. .SH "KONFORM ZU" .\" 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() erschien erstmals in 4.2BSD). .SH ANMERKUNGEN POSIX.1 erfordert nicht, dass \fI\fP eingebunden wird. Diese Header\-Datei ist in Linux nicht erforderlich. Allerdings benötigen einige historische Implementierungen (BSD) diese Header\-Datei. Es wird empfohlen, sie für portierbare Anwendungen einzubinden. .PP Für Hintergrundinformationen zum Typ \fIsocklen_t\fP siehe \fBaccept\fP(2). .SH FEHLER .\" FIXME Document transparent proxy options Die transparenten Proxy\-Optionen sind nicht beschrieben. .SH BEISPIEL Ein Beispiel für die Verwendung von \fBbind\fP() mit Internet Domain Sockets finden Sie in \fBgetaddrinfo\fP(3). .PP .\" listen.7 refers to this example. .\" accept.7 refers to this example. .\" unix.7 refers to this example. Das folgende Beispiel zeigt, wie ein Stream Socket in die UNIX\-Domain (\fBAF_UNIX\fP) eingebunden wird und Verbindungen annimmt: .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)); /* Struktur zurücksetzen */ 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"); /* Jetzt können wir eingehende Verbindungen nacheinander mit accept(2) annehmen. */ peer_addr_size = sizeof(struct sockaddr_un); cfd = accept(sfd, (struct sockaddr *) &peer_addr, &peer_addr_size); if (cfd == \-1) handle_error("accept"); /* Code für die Behandlung eingehender Verbindungen … */ /* Wenn er nicht mehr gebraucht wird, sollte der Pfadname des Sockets (MY_SOCK_PATH) mit unlink(2) oder remove(3) gelöscht werden */ } .EE .SH "SIEHE AUCH" \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 KOLOPHON Diese Seite ist Teil der Veröffentlichung 4.16 des Projekts Linux\-\fIman\-pages\fP. Eine Beschreibung des Projekts, Informationen, wie Fehler gemeldet werden können sowie die aktuelle Version dieser Seite finden sich unter \%https://www.kernel.org/doc/man\-pages/. .SH ÜBERSETZUNG Die deutsche Übersetzung dieser Handbuchseite wurde von Hanno Wagner , Martin Eberhard Schauer und Mario Blättermann erstellt. Diese Übersetzung ist Freie Dokumentation; lesen Sie die GNU General Public License Version 3 oder neuer bezüglich der Copyright-Bedingungen. Es wird KEINE HAFTUNG übernommen. Wenn Sie Fehler in der Übersetzung dieser Handbuchseite finden, schicken Sie bitte eine E-Mail an .