source: trunk/third/ssh/socketpair.c @ 10564

Revision 10564, 1.6 KB checked in by danw, 27 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r10563, which included commits to RCS files with non-trunk default branches.
Line 
1/* 
2
3   socketpair() emulator for System V Release 3
4
5   socketpair driver included here ignores all the standard
6   socketpair() parameters except the file descriptors.
7
8   s_pipe() is by W. Richard Stevens from the book titled
9   "Unix Network Programming"  ISBN 0-13-949876-1  1990
10
11*/
12
13#include "includes.h"
14#include <sys/stream.h>                /* defines queue_t */
15#include <stropts.h>                   /* defines strfdinsert */
16
17#define SPX_DEVICE  "/dev/spx"
18
19
20int socketpair(int a_family, int s_type, int s_protocol, int s_fd)
21{
22  return s_pipe(s_fd);
23}
24
25
26int s_pipe(int  fd[2])
27{
28  struct strfdinsert    ins;
29  queue_t               *pointer;
30
31  /*
32   * Open the stream clone device "/dev/spx" twice,
33   * obtaining two file descriptors.
34   */
35
36  if ((fd[0] = open(SPX_DEVICE, O_RDWR)) < 0)
37    return(-1);
38
39  if ((fd[1] = open(SPX_DEVICE, O_RDWR)) < 0) {
40    close(fd[0]);
41    return(-1);
42  }
43
44  /*
45   * Now link these two streams together with an I_FDINSERT ioctl.
46   */
47
48  ins.ctlbuf.buf     = (char *) &pointer;  /* no ctl info, just the ptr */
49  ins.ctlbuf.maxlen  = sizeof(queue_t *);
50  ins.ctlbuf.len     = sizeof(queue_t *);
51
52  ins.databuf.buf    = (char *) 0;         /* no data to send */
53  ins.databuf.maxlen = 0;
54  ins.databuf.len    = -1;        /* magic! must be -1 not 0 for stream pipe */
55 
56  ins.fildes = fd[1];      /* the fd to connect with fd[0] */
57  ins.flags  = 0;          /* nonpriority message */
58  ins.offset = 0;          /* offset of pointer in control buffer */
59
60  if (ioctl(fd[0], I_FDINSERT, (char *) &ins) < 0) {
61    close(fd[0]);
62    close(fd[1]);
63    return(-1);
64  }
65
66  return(0);               /* tutto posto */
67
68}
Note: See TracBrowser for help on using the repository browser.