glibc/manual/examples/mkfsock.c
Ulrich Drepper 356d71003e Update.
1998-04-07  Andreas Jaeger  <aj@arthur.rhein-neckar.de>

	* sysdeps/unix/sysv/linux/bits/sockunion.h: Fix error message.

	* manual/socket.texi (Interface Naming): Fix typo.

1998-04-07  Andreas Jaeger  <aj@arthur.rhein-neckar.de>

	* manual/examples/filesrv.c (main): Remove filename first.

	* manual/socket.texi (Address Formats): Change ?F_LOCAL, ?F_FILE,
	?F_UNIX.

	* manual/examples/mkfsock.c (make_named_socket): Use PF_LOCAL
	instead of PF_UNIX.

	* manual/examples/filecli.c (main): Use AF_LOCAL
	instead of AF_UNIX.

1998-04-09  Ulrich Drepper  <drepper@cygnus.com>

	* sysdeps/libm-ieee754/s_signgam.c: Define __signgam and make
	signgam weak alias.
	* sysdeps/libm-ieee754/w_lgamma.c: Use __signgam not signgam.
	* sysdeps/libm-ieee754/w_lgammaf.c: Likewise.
	* sysdeps/libm-ieee754/w_lgammal.c: Likewise.
	* sysdeps/libm-ieee754/w_gamma.c: Likewise.
	* sysdeps/libm-ieee754/w_gammaf.c: Likewise.
	* sysdeps/libm-ieee754/w_gammal.c: Likewise.

	* login/utmp_daemon.c (open_socket): Use __connect not connect.

	* sysdeps/unix/bsd/bsd4.4/bits/sockaddr.h (SA_LEN): New macro.
	* Makerules: Re-add missing rule for $(objpfx)stamp.oS.
1998-04-09 14:14:20 +00:00

45 lines
940 B
C

#include <stddef.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/un.h>
int
make_named_socket (const char *filename)
{
struct sockaddr_un name;
int sock;
size_t size;
/* Create the socket. */
sock = socket (PF_LOCAL, SOCK_DGRAM, 0);
if (sock < 0)
{
perror ("socket");
exit (EXIT_FAILURE);
}
/* Bind a name to the socket. */
name.sun_family = AF_LOCAL;
strncpy (name.sun_path, filename, sizeof (name.sun_path));
/* The size of the address is
the offset of the start of the filename,
plus its length,
plus one for the terminating null byte.
Alternativly you can just do:
size = SUN_LEN (&name);
*/
size = (offsetof (struct sockaddr_un, sun_path)
+ strlen (name.sun_path) + 1);
if (bind (sock, (struct sockaddr *) &name, size) < 0)
{
perror ("bind");
exit (EXIT_FAILURE);
}
return sock;
}