[comp.sys.apollo] Problem with socket based IPC on Apollo DN3000

rzmul2@tuvie (Uni Leoben) (01/10/88)

Problem with socket based IPC on Apollo DN3000

Hi everybody,

I'm posting this for a friend who has no Usenet connection (yet) :

The following little piece of code should demonstrate interprocess
communication between a server running as a background process
and a client which can be run as a program from the user's console.
It's taken from Maurice Bach, "The Design of the UNIX Operating System",
ISBN 0-13-201799-7 025,Prentice Hall, while the syserr() function
is from Rochkind, "Advanced Unix Programming".
The problem is that the example does not run on my DN3000
Domain/IX SR9.6-BSD4.2. Can anyone run it on his/her machine and tell me
if it's running there and what probably could be wrong. I'd appreciate
any replies via e-mail.

-- Tom Leitner (rzmul2@tuvie.uucp)

Here comes the code:
-----snip-----snip-----snip-----snip-----snip-----snip-----snip-----snip------
# To recover, type sh archive
echo restoring Makefile
sed 's/^X//' > Makefile <<\XxXxXxXxXx-EOF-XxXxXxXxXx
Xall:   server client testit
Xserver:   server.o syserr.o
X   cc -o server server.o syserr.o
Xclient:   client.o syserr.o 
X   cc -o client client.o syserr.o
Xtestit:   server client
X   server & client
XxXxXxXxXx-EOF-XxXxXxXxXx
echo restoring server.c
sed 's/^X//' > server.c <<\XxXxXxXxXx-EOF-XxXxXxXxXx
X#include <sys/types.h>
X#include <sys/socket.h>
X#include <netinet/in.h>
X
Xmain()
X{
X   int sd,ns;
X   char buf[256];
X   struct sockaddr sockaddr;
X   int pid,n;
X   int fromlen = sizeof (sockaddr);
X
X   pid = getpid(); 
X
X   sd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
X              /* returns an i/o error already !!! ???? Why?
X                  I tried different combinations             */
X   if(sd == -1)
X      syserr("socket");
X
X   /* bind name - don't include null char in the name */
X
X   if(bind(sd,"sockname",sizeof("sockname")-1)== -1)
X      syserr("bind");
X   if(listen(sd,1)==-1)
X      syserr("listen");
X
X   for(;;)
X   {
X
X      ns = accept(sd,&sockaddr,&fromlen); /* accept should wait,
X                         on my DN3000 it does an i/o error
X                         instead */
X      if(ns == -1)
X         syserr("accept");
X   
X      if(fork() == 0)
X      {
X         /* child */
X         close (sd);
X         n=read(ns,buf,sizeof(buf));
X         printf("(%d) server read  %d '%s'\n",pid,n,buf);
X         exit();
X      }
X      close(ns);
X   }
X}
X
XxXxXxXxXx-EOF-XxXxXxXxXx
echo restoring client.c
sed 's/^X//' > client.c <<\XxXxXxXxXx-EOF-XxXxXxXxXx
X#include <sys/types.h>
X#include <sys/socket.h>
X
Xmain()
X{
X   int sd,ns;
X   char buf[256];
X   struct sockaddr sockaddr;
X   int fromlen;
X
X   sd = socket(AF_UNIX,SOCK_STREAM,0);
X   
X   /* connect to name - null char is not part of name */
X   if(connect(sd,"sockname",sizeof("sockname") -1) == -1)
X      exit();
X
X   write(sd,"hi guy",6);
X}
XxXxXxXxXx-EOF-XxXxXxXxXx
echo restoring syserr.c
sed 's/^X//' > syserr.c <<\XxXxXxXxXx-EOF-XxXxXxXxXx
X#include <stdio.h>
Xvoid
Xsyserr(msg)
Xchar *msg;
X{
X   extern int errno,sys_nerr;
X   extern char *sys_errlist[];
X
X   fprintf(stderr,"ERROR: %s (%d",msg,errno);
X   if (errno >0 && errno < sys_nerr)
X      fprintf(stderr,";%s)\n",sys_errlist[errno]);
X   else
X      fprintf(stderr,")\n");
X   exit(1);
X}
X
Xvoid
Xfatal(msg) /* print error message and terminate */
Xchar *msg;
X{
X   fprintf(stderr,"ERROR: %s\n",msg);
X   exit(1);
X}
XxXxXxXxXx-EOF-XxXxXxXxXx
exit 0
-----snip-----snip-----snip-----snip-----snip-----snip-----snip-----snip------

benoni@ssc-vax.UUCP (Charles L Ditzel) (01/12/88)

In article <552@tuvie>, rzmul2@tuvie (Uni Leoben) writes:
> Problem with socket based IPC on Apollo DN3000
> Hi everybody,
> I'm posting this for a friend who has no Usenet connection (yet) :
...
> The problem is that the example does not run on my DN3000
...
> #include <sys/types.h>
> #include <sys/socket.h>
> #include <netinet/in.h>
> 
> main()
> {
>    int sd,ns;
....
> 
>    pid = getpid(); 
>    sd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
>               /* returns an i/o error already !!! ???? Why?
>                   I tried different combinations             */
....

Yes, I too had problems with sockets on a dn3000, I didn't have
time to solve the problem (get the uw server running) and I never
got back to it (the real world interfered).  

My dn3000 was running (sr9.6) bsd4.2.

The code I was compiling had previously compiled with no problems 
on a BSD4.3 VAX 11/780.

Now that you remind me, I would like to get back to trying to get
uw on the Apollo...but it on hinges figuring out why it dies in the
same place.