Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!wuarchive!rex!uflorida!atlantis.cis.ufl.edu!leh From: leh@atlantis.cis.ufl.edu (Les Hill) Newsgroups: comp.lang.c Subject: Re: Sending struct through DGRAM socket Message-ID: <28096@uflorida.cis.ufl.EDU> Date: 19 Apr 91 14:37:30 GMT References: <14918@helios.TAMU.EDU> Sender: news@uflorida.cis.ufl.EDU Reply-To: leh@atlantis.cis.ufl.edu (Les Hill) Distribution: na Organization: U of Florida. Computer Science Dept. Lines: 35 In article <14918@helios.TAMU.EDU>, greg@carnivore.tamu.edu (Greg Economides) writes: |> I am trying to communicate with a forked process using a DGRAM socket |> (AF_UNIX) on a Sun 386i (OS 4.0.2). What I really want to send through |> the socket is a small struct (about five float fields). I have been |> using the `sendto' and `read' functions which need a (char *) to send |> through the socket. These work fine with character strings, but do not |> do so well with structs. |> |> Is there a quick/clean way to translate a struct into a character stream |> (and then a way to get the struct back) so that it can be sent using these |> functions? Is there a better or more straight-forward way of doing this? |> I am still quite a fledgling sockets programmer. |> Greg Economides "This sentence is false" |> Technical Lab Coordinator |> Texas A&M University -- Biosystems Modelling Group |> Internet: greg@carnivore.tamu.edu If the processes are on the same machine, shared memory (shmctl, shmget, shmop, shmat, shmdt) if available (dont have a 386i to look at) might be a viable alternative [dont forget the key routine (whose name escapes me at the moment.)] If you are bent on sending it over the socket, try this: err = sendto(s, (char *)&mystruct, sizeof mystruct, to, tolen); After all, there is nothing magic about character streams :) BTW, the above is a BAD thing to depend on if this will be ported to any other architectures (including other Suns!) Les Hill -- Extraordinary crimes against the people and the state have to be avenged by agents extraordinary. Two such people are John Steed -- top professional, and his partner, Emma Peel -- talented amateur; otherwise known as "The Avengers." INTERNET: leh@ufl.edu UUCP: ...!gatech!uflorida!leh BITNET: vishnu@UFPINE