Binding Socket Addresses To Unix Domain Datagram Sockets - HP Rp3440-4 - 9000 - 0 MB RAM Programmer's Manual

Bsd sockets interface programmer’s guide
Hide thumbs Also See for Rp3440-4 - 9000 - 0 MB RAM:
Table of Contents

Advertisement

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:
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
System call:
bind(s, addr, addrlen);
int s;
struct sockaddr_un *addr;
int addrlen;
Parameter
Description of Contents
s
socket descriptor of local
socket
addr
socket address
addrlen
length of socket address
Function result: 0 if bind is successful, -1 if bind fails.
Example:
#include <sys/type.h>
#include <sys/socket.h>
#include <sys/un.h>
#define
struct
...
servaddr.sun_family = AF_UNIX;
Chapter 7
Using UNIX Domain Datagram Sockets
Writing the Server and Client Processes
SOCKET_PATH "/tmp/myserver"
sockaddr_un
servaddr;
INPUT Value
socket descriptor of
socket to be bound
pointer to address to be
bound to s
size of struct
sockaddr_un address
153

Advertisement

Table of Contents
loading

Table of Contents