HP Rp7410 BSD Sockets Interface Programmer's Guide - Page 153
Binding Socket Addresses to UNIX Domain, Datagram Sockets
View all HP Rp7410 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 153 highlights
Using UNIX Domain Datagram Sockets Writing the Server and Client Processes Binding Socket Addresses to UNIX Domain Datagram Sockets After your server process has created a socket, it must call bind to bind a socket address. Until the server socket is bound to an address, other processes have no way to reference it. The server process must bind a specific pathname to its socket. Set up the address structure with a local address before the server makes a call to bind. The bind system call creates the inode file. If the inode file is not deallocated after bound sockets are closed, the names will continue to exist and cause directories to fill up with the unused files. To avoid directories filling up with these unused files, you can remove the files by calling unlink or remove them manually with the rm command. bind and its parameters are described in the following table. Include files: System call: #include #include #include bind(s, addr, addrlen); int s; struct sockaddr_un *addr; int addrlen; Parameter Description of Contents INPUT Value s addr addrlen socket descriptor of local socket socket address length of socket address socket descriptor of socket to be bound pointer to address to be bound to s size of struct sockaddr_un address Function result: 0 if bind is successful, -1 if bind fails. Example: #include #include #include #define SOCKET_PATH "/tmp/myserver" struct sockaddr_un servaddr; ... servaddr.sun_family = AF_UNIX; Chapter 7 153