binding sockets
Jonathan I. Kamens
jik at athena.mit.edu
Mon Sep 17 04:37:30 AEST 1990
In article <ERAN.90Sep14175746 at adelbert9.stanford.edu>, eran at adelbert9.stanford.edu (eran yehudai) writes:
|> It seems the namelen parameter one passes bind() should be
|> 2 + strlen(socketname), and then everything works.
No, actually, the namelen parameter one passes to bind() should be the
sizeof the sockaddr structure being passed into it, e.g. (error checking
omitted):
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <strings.h>
struct sockaddr_un name;
int s;
name.sun_family = AF_UNIX;
strcpy(name.sun_path, "/tmp/testsocket");
s = socket(PF_UNIX, SOCK_STREAM, 0);
bind(s, &name, sizeof(name));
--
Jonathan Kamens USnail:
MIT Project Athena 11 Ashford Terrace
jik at Athena.MIT.EDU Allston, MA 02134
Office: 617-253-8495 Home: 617-782-0710
More information about the Comp.unix.programmer
mailing list