#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stropts.h>
#include <stdio.h>
#define TESTFILE "/dev/null"
main(int argc, char * argv)
{
	int 		fd;
	int 		pipefd[2];
	struct 		stat statbuf;
	stat(TESTFILE, &statbuf);
	statout(TESTFILE, &statbuf);
	pipe(pipefd);
	if (fork() == 0) {
		close(pipefd[0]);
		sendfd(pipefd[1]);
	} else {
		close(pipefd[1]);
		recvfd(pipefd[0]);
	}
}
sendfd(int p)
{
	int 		tfd;
	tfd = open(TESTFILE, O_RDWR);
	ioctl(p, I_SENDFD, tfd);
}
recvfd(int p)
{
	struct 		strrecvfd rfdbuf;
	struct 		stat statbuf;
	char		fdbuf[32];
	ioctl(p, I_RECVFD, &rfdbuf);
	fstat(rfdbuf.fd, &statbuf);
	sprintf(fdbuf, "recvfd=%d", rfdbuf.fd);
	statout(fdbuf, &statbuf);	
}
statout(char *f, struct stat *s)
{
	printf("stat: from=%s mode=0%o, ino=%d, dev=%d, rdev=%d\n",
		f, s->st_mode, s->st_ino, s->st_dev, s->st_rdev);
	fflush(stdout);
}
