BIND(2)BIND(2)NAMEbind - bind a name to a socket
SYNOPSIS
#include <sys/types.h>
#include <sys/socket.h>
int bind (int s, const struct sockaddr *name, socklen_t namelen);
#if _XOPEN_SOURCE >= 500
int bind (int s, const struct sockaddr *name, socklen_t namelen);
#elif _XOPEN_SOURCE < 500
int bind (int s, const struct sockaddr *name, size_t namelen);
#endif
DESCRIPTION
Bind assigns a name to an unnamed socket. When a socket is created with
socket(2) it exists in a name space (address family) but has no name
assigned. Bind requests that name be assigned to the socket.
The rules used in name binding vary between communication domains.
Consult the protocol manual entries in section 7 for detailed
information.
RETURN VALUE
If the bind is successful, a 0 value is returned. A return value of -1
indicates an error, which is further specified in the global errno.
ERRORS
The bind call will fail if:
[EBADF] S is not a valid descriptor.
[ENOTSOCK] S is not a socket.
[EADDRNOTAVAIL] The specified address is not available from the local
machine.
[EADDRINUSE] The specified address is already in use.
[EINVAL] The socket is already bound to an address.
[EACCES] The requested address is protected, and the current
user has inadequate permission to access it.
[EFAULT] The name parameter is not in a valid part of the user
address space.
See also the protocol-specific manual pages for other error values.
Page 1
BIND(2)BIND(2)SEE ALSOconnect(2), listen(2), socket(2), tcp(7P), udp(7P), unix(7F)NOTES
ABI-compliant versions of the above call can be obtained from
libsocket.so.
There are three types of bind functions in n32 and 64 bit C libraries for
IRIX 6.5.19 and later versions. One is the normal type when _XOPEN_SOURCE
is not defined; the second is XPG5 type when _XOPEN_SOURCE is set to >=
500; and the third is XPG4 type when _XOPEN_SOURCE set to < 500. The
difference between these functions is in the third argument type to bind.
Refer <sys/socket.h> for alternate definitions of socklen_t type.
1. For the normal case when _XOPEN_SOURCE is not defined, third
argument type, socklen_t, will be an int and the normal bind is
used.
2. When _XOPEN_SOURCE is set to >= 500, third argument type,
socklen_t, will be u_int32_t type and xpg5 type function will be
used.
3. When _XOPEN_SOURCE is set to < 500, third argument type will be a
size_t and xpg4 type function will be used.
XPG5 type function is not supported in o32 C library.
The XPG5 type bind function is actually defined as a static inline
function in <sys/socket.h>, and it calls a new function _xpg5_bind which
is specific to IRIX 6.5.19 and later. Therefore applications that call
XPG5 type bind should check the existence of the new symbol.
#include <sys/socket.h>
#include <optional_sym.h>
if (_MIPS_SYMBOL_PRESENT(_xpg5_bind)) {
bind(s, &addr, addrlen);
} else {
...
}
Because the static inline function is defined in each source file that
includes <sys/socket.h>, these static functions will have different
addresses in any cases that inline expansion is not performed. This may
cause problems if the address of the function is examined in programs.
To avoid this problem, use -D_XPG5_BIND_USER_DEFINED compile option to
disable the static inline definition in <sys/socket.h>, and define a user
defined function with below definition:
int *
bind(int _s, struct sockaddr *_addr, socklen_t *_addrlen)
{
return(_xpg5_bind(_s, _addr, _addrlen));
}
Page 2
BIND(2)BIND(2)
Use the compile option always, when a user defined XPG5 bind function is
required.
Page 3