#include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <sys/ndd_var.h> /*Needed for AF_NDD address family only*/ #include <sys/atmsock.h> /*Needed for SOCK_CONN_DGRAM socket type only*/
int bind (Socket, Name, NameLength) int Socket; const struct sockaddr *Name; size_t NameLength;
The bind subroutine assigns a Name parameter to an unnamed socket. Sockets created by the socket subroutine are unnamed; they are identified only by their address family. Subroutines that connect sockets either assign names or use unnamed sockets.
In the case of a UNIX domain socket, a connect call only succeeds if the process that calls connect has read and write permissions on the socket file created by the bind call. Permissions are determined by the umask value of the process that created the file.
An application program can retrieve the assigned socket name with the getsockname subroutine.
Upon successful completion, the bind subroutine returns a value of 0.
If the bind subroutine is unsuccessful, the subroutine handler performs the following actions:
The bind subroutine is unsuccessful if any of the following errors occurs:
The following program fragment illustrates the use of the bind subroutine to bind the name "/tmp/zan/" to a UNIX domain socket.
#include <sys/un.h>
. . . struct sockaddr_un addr; . . . strcpy(addr.sun_path, "/tmp/zan/"); addr.sun_len = strlen(addr.sun_path); addr.sun_family = AF_UNIX; bind(s,(struct sockaddr*)&addr, SUN_LEN(&addr));
The bind subroutine is part of Base Operating System (BOS) Runtime.
The socket applications can be compiled with COMPAT_43 defined. This will make the sockaddr structure BSD 4.3 compatible. For more details refer to socket.h.
Binding a name in the UNIX domain creates a socket in the file system that must be deleted by the caller when it is no longer needed.
The connect subroutine, getsockname subroutine, listen subroutine, socket subroutine.
Binding Names to Sockets, Reading UNIX Datagrams Example Program, Sockets Overview, Understanding Socket Connections, and Understanding Socket Creation in AIX Version 4.3 Communications Programming Concepts.