5 #include <sys/socket.h>
9 make_named_socket (const char *filename
)
11 struct sockaddr_un name
;
15 /* Create the socket. */
16 sock
= socket (PF_LOCAL
, SOCK_DGRAM
, 0);
23 /* Bind a name to the socket. */
24 name
.sun_family
= AF_LOCAL
;
25 strncpy (name
.sun_path
, filename
, sizeof (name
.sun_path
));
27 /* The size of the address is
28 the offset of the start of the filename,
30 plus one for the terminating null byte.
31 Alternatively you can just do:
32 size = SUN_LEN (&name);
34 size
= (offsetof (struct sockaddr_un
, sun_path
)
35 + strlen (name
.sun_path
) + 1);
37 if (bind (sock
, (struct sockaddr
*) &name
, size
) < 0)