xref: /csrg-svn/lib/libc/sys/bind.2 (revision 47208)
136759Sbostic.\" Copyright (c) 1983 The Regents of the University of California.
236759Sbostic.\" All rights reserved.
320207Smckusick.\"
443568Strent.\" %sccs.include.redist.man%
520207Smckusick.\"
6*47208Scael.\"     @(#)bind.2	6.9 (Berkeley) 03/10/91
736759Sbostic.\"
8*47208Scael.Dd
9*47208Scael.Dt BIND 2
10*47208Scael.Os BSD 4.2
11*47208Scael.Sh NAME
12*47208Scael.Nm bind
13*47208Scael.Nd bind a name to a socket
14*47208Scael.Sh SYNOPSIS
15*47208Scael.Fd #include <sys/types.h>
16*47208Scael.Fd #include <sys/socket.h>
17*47208Scael.Ft int
18*47208Scael.Fn bind "int s" "struct sockaddr *name" "int namelen"
19*47208Scael.Sh DESCRIPTION
20*47208Scael.Fn Bind
2120207Smckusickassigns a name to an unnamed socket.
2220207SmckusickWhen a socket is created
2320207Smckusickwith
24*47208Scael.Xr socket 2
2520207Smckusickit exists in a name space (address family)
2620207Smckusickbut has no name assigned.
27*47208Scael.Fn Bind
2828359Sannerequests that
29*47208Scael.Fa name
3020207Smckusickbe assigned to the socket.
31*47208Scael.Sh NOTES
3220207SmckusickBinding a name in the UNIX domain creates a socket in the file
3323792Ssechrestsystem that must be deleted by the caller when it is no longer
3420207Smckusickneeded (using
35*47208Scael.Xr unlink 2 ) .
36*47208Scael.Pp
3720207SmckusickThe rules used in name binding vary between communication domains.
3820207SmckusickConsult the manual entries in section 4 for detailed information.
39*47208Scael.Sh RETURN VALUES
4020207SmckusickIf the bind is successful, a 0 value is returned.
41*47208ScaelA return value of -1 indicates an error, which is
42*47208Scaelfurther specified in the global
43*47208Scael.Va errno .
44*47208Scael.Sh ERRORS
45*47208ScaelThe
46*47208Scael.Fn bind
47*47208Scaelcall will fail if:
48*47208Scael.Bl -tag -width EADDRNOTAVA
49*47208Scael.It Bq Er EBADF
50*47208Scael.Fa S
51*47208Scaelis not a valid descriptor.
52*47208Scael.It Bq Er ENOTSOCK
53*47208Scael.Fa S
54*47208Scaelis not a socket.
55*47208Scael.It Bq Er EADDRNOTAVAIL
5620207SmckusickThe specified address is not available from the local machine.
57*47208Scael.It Bq Er EADDRINUSE
5820207SmckusickThe specified address is already in use.
59*47208Scael.It Bq Er EINVAL
6020207SmckusickThe socket is already bound to an address.
61*47208Scael.It Bq Er EACCES
6220207SmckusickThe requested address is protected, and the current user
6320207Smckusickhas inadequate permission to access it.
64*47208Scael.It Bq Er EFAULT
65*47208ScaelThe
66*47208Scael.Fa name
67*47208Scaelparameter is not in a valid part of the user
6820207Smckusickaddress space.
69*47208Scael.El
70*47208Scael.Pp
7121004SmckusickThe following errors are specific to binding names in the UNIX domain.
72*47208Scael.Bl -tag -width EADDRNOTAVA
73*47208Scael.It Bq Er ENOTDIR
7421004SmckusickA component of the path prefix is not a directory.
75*47208Scael.It Bq Er EINVAL
7621004SmckusickThe pathname contains a character with the high-order bit set.
77*47208Scael.It Bq Er ENAMETOOLONG
7821004SmckusickA component of a pathname exceeded 255 characters,
7921004Smckusickor an entire path name exceeded 1023 characters.
80*47208Scael.It Bq Er ENOENT
8121004SmckusickA prefix component of the path name does not exist.
82*47208Scael.It Bq Er ELOOP
8321004SmckusickToo many symbolic links were encountered in translating the pathname.
84*47208Scael.It Bq Er EIO
8521004SmckusickAn I/O error occurred while making the directory entry or allocating the inode.
86*47208Scael.It Bq Er EROFS
8721004SmckusickThe name would reside on a read-only file system.
88*47208Scael.It Bq Er EISDIR
89*47208ScaelAn empty pathname was specified.
90*47208Scael.El
91*47208Scael.Sh SEE ALSO
92*47208Scael.Xr connect 2 ,
93*47208Scael.Xr listen 2 ,
94*47208Scael.Xr socket 2 ,
95*47208Scael.Xr getsockname 2
96*47208Scael.Sh HISTORY
97*47208ScaelThe
98*47208Scael.Nm
99*47208Scaelfunction call appeared in
100*47208Scael.Bx 4.2 .
101