home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d1xx
/
d145
/
dnet.lha
/
Dnet
/
unix
/
test
/
test.c
< prev
Wrap
C/C++ Source or Header
|
1988-05-26
|
1KB
|
82 lines
/*
* TEST.C
*
* create a socketpair()
* chdir into NET1
* filedes #2 = LOG
* filedes #0 = first pair
* fork/exec
*
* chdir into NET2
* filedes #2 = LOG
* etc..
*
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <sys/file.h>
char *arg;
main(ac,av)
char *av[];
{
int des[2];
int fd;
int error;
arg = av[1]; /* NULL ok */
error = socketpair(AF_UNIX, SOCK_STREAM, 0, des);
negerr(error, "socketpair");
if (chdir("NET1") < 0) {
puts("Unable to CD NET1");
exit(1);
}
fd = open("LOG", O_WRONLY|O_CREAT|O_TRUNC, 0666);
dnet(des[0], fd);
if (chdir("../NET2") < 0) {
puts("Unable to CD NET2");
exit(1);
}
fd = open("LOG", O_WRONLY|O_CREAT|O_TRUNC, 0666);
dnet(des[1], fd);
}
dnet(comfd, logfd)
{
int o0 = dup(0);
int o1 = dup(1);
int o2 = dup(2);
dup2(comfd, 0);
dup2(logfd, 1);
dup2(logfd, 2);
if (fork() == NULL) {
fcntl(0, F_SETOWN, getpid());
execlp("dnet", "dnet", arg, NULL);
puts("unable to find DNET");
exit(1);
}
dup2(o0, 0);
dup2(o1, 1);
dup2(o2, 2);
close(o0);
close(o1);
close(o2);
}
negerr(error, str)
char *str;
{
if (error < 0) {
perror(str);
exit(1);
}
}