Path: utzoo!utgpu!water!watmath!clyde!rutgers!sunybcs!boulder!hao!gatech!mcnc!decvax!decwrl!sun!pitstop!sundc!seismo!uunet!mcvax!tuvie!rzmul2 From: rzmul2@tuvie (Uni Leoben) Newsgroups: comp.sys.apollo Subject: Problem with socket based IPC on Apollo DN3000 Keywords: IPC DN3000 sockets Message-ID: <552@tuvie> Date: 9 Jan 88 20:30:05 GMT Organization: TU Vienna EDP-Center, Vienna, AUSTRIA Lines: 133 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 X#include X#include 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 X#include 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 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------