Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!cbatt!ihnp4!ihdev!pdg From: pdg@ihdev.UUCP Newsgroups: comp.unix.questions Subject: Re: System V.2 IPC (msgop - message passing) ? Message-ID: <1319@ihdev.ATT.COM> Date: Sat, 11-Apr-87 17:07:26 EST Article-I.D.: ihdev.1319 Posted: Sat Apr 11 17:07:26 1987 Date-Received: Wed, 15-Apr-87 01:29:47 EST References: <419@artecon.artecon.UUCP> Reply-To: pdg@ihdev.UUCP (Joe Isuzu) Organization: American Nasal Amputation Centre Lines: 48 Keywords: Include file definitions In article <419@artecon.artecon.UUCP> tony@artecon.artecon.UUCP (Anthony D. Parkhurst) writes: >Question about System V message passing (IPC): > [ manual page excerpt editied out ] >However, looking at the include file when this is defined , >it defines the structure like this: > >struct msgbuf { > int mtype; > char mtext[1]; /* note the '1' */ > } > >What is going on here, I can't redefine this pointer, and I certainly >can't pass descent messages in *1* byte. They don't expect you to. Just because it is one byte long in the msgbuf definition, doesn't mean you must only pass 1 byte at a time. You just allocate more space at the end of the structure, and reference the space as mtext[index]. The standard SysV compiler does not do any array-bounds checking, so this is OK. Take the following example (an excerpt from the client side of my SysV version of the GNU client/server code) struct msgbuf *msgp = (struct msgbuf *)malloc(sizeof(struct msgbuf)+ 256); ...... (void)strcpy(msgp->mtext,out); msgp->mtype = 1; if(msgsnd(msgqid,msgp,sizeof(struct msgbuf)+strlen(out)+1,1)==-1) { perror("msg send "); exit(1); } ..... So anyway, I just allocate a message 256b + sizeof (msgbuf) long, then use it again and again, by copying what I want to send into the message, and sending it, specifying the size of what I want to send, not the size of what I alloced. This works well, and is a pretty standard usage. -- Paul Guthrie ihnp4!ihdev!pdg This Brain left intentionally blank.