Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP (Chris Torek) Newsgroups: net.unix-wizards Subject: Re: Socket Addresses Message-ID: <2731@umcp-cs.UUCP> Date: Mon, 4-Aug-86 20:58:39 EDT Article-I.D.: umcp-cs.2731 Posted: Mon Aug 4 20:58:39 1986 Date-Received: Tue, 5-Aug-86 03:55:46 EDT References: <155@sauron.OZ> <2725@umcp-cs.UUCP> Reply-To: chris@maryland.UUCP (Chris Torek) Organization: University of Maryland, Dept. of Computer Sci. Lines: 58 In article <2725@umcp-cs.UUCP> I wrote: > int s; > struct sockaddr_un name; > > s = socket(AF_UNIX, SOCK_STREAM, 0); > ... > name.sun_family = AF_UNIX; > name.sun_name = "server"; > if (bind(s, (struct sockaddr *) &name, strlen(name.sun_name))) ... Ai! This is all wrong (and will not even compile)! Better (tested even): #include #include #include char *strcpy(*); /*ARGSUSED*/ main(argc, argv) int argc; char **argv; { int s; struct sockaddr_un name; if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { perror("socket"); exit(1); } name.sun_family = AF_UNIX; (void) strcpy(name.sun_path, "server"); (void) unlink(name.sun_path); /* delete previous socket, if any */ if (bind(s, (struct sockaddr *) &name, sizeof (name.sun_family) + strlen(name.sun_path))) { perror("bind"); exit(1); } /* * Thanks to John Bruner for pointing out the missing * sizeof name.sun_family. The rest of the corrections are * from the revised 4.3 IPC primer---I should have known, * since I helped revise it, and we tried to ensure that all * the examples worked. * * Incidentally, there is a hidden assumption about structure * padding even in the above. This `path name' business needs * work. */ exit(0); } -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@mimsy.umd.edu