The bind() call sets the local address and port of a socket.
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
...
int err;
struct sockaddr_un local_addr;
/* Try to delete the socket file, in case it was left behind the last
* time this program was run. */
unlink ("/tmp/server-sock");
local_addr.sun_family = AF_UNIX;
strcpy (local_addr.sun_path, "/tmp/server-sock");
err = bind (s, (struct sockaddr *) &local_addr, sizeof local_addr);
if (err < 0) perror ("bind failed");
|