5 * Rob Zimmermann. All rights reserved.
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
14 #include <sys/types.h>
15 #include <sys/queue.h>
18 #include <bitstring.h>
28 #include "../common/common.h"
31 static int vi_send_
__P((IPVIWIN
*, int));
32 static int vi_send_1
__P((IPVIWIN
*, int, u_int32_t
));
33 static int vi_send_12
__P((IPVIWIN
*ipvi
, int code
, u_int32_t val1
, u_int32_t val2
));
34 static int vi_send_ab1
__P((IPVIWIN
*ipvi
, int code
,
35 const char *str1
, u_int32_t len1
,
36 const char *str2
, u_int32_t len2
, u_int32_t val
));
37 static int vi_send_a1
__P((IPVIWIN
*ipvi
, int code
, const char *str
, u_int32_t len
,
39 static int vi_send_a
__P((IPVIWIN
*ipvi
, int code
, const char *str
, u_int32_t len
));
43 static int vi_set_ops
__P((IPVIWIN
*, IPSIOPS
*));
44 static int vi_win_close
__P((IPVIWIN
*));
46 static int vi_close
__P((IPVI
*));
47 static int vi_new_window
__P((IPVI
*, IPVIWIN
**, int));
52 * PUBLIC: int vi_create __P((IPVI **, u_int32_t));
55 vi_create(IPVI
**ipvip
, u_int32_t flags
)
59 MALLOC_GOTO(NULL
, ipvi
, IPVI
*, sizeof(IPVI
));
60 memset(ipvi
, 0, sizeof(IPVI
));
65 ipvi
->new_window
= vi_new_window
;
66 ipvi
->close
= vi_close
;
77 vi_new_window (IPVI
*ipvi
, IPVIWIN
**ipviwinp
, int fd
)
81 MALLOC_GOTO(NULL
, ipviwin
, IPVIWIN
*, sizeof(IPVIWIN
));
82 memset(ipviwin
, 0, sizeof(IPVIWIN
));
85 ipviwin
->ifd
= ipvi
->ifd
;
86 ipviwin
->ofd
= ipvi
->ofd
;
94 socketpair(AF_LOCAL
, SOCK_STREAM
, 0, sockets
);
99 mh
.msg_controllen
= sizeof(ch
);
100 mh
.msg_control
= (void *)&ch
;
103 iov
.iov_base
= &dummy
;
105 ch
.header
.cmsg_level
= SOL_SOCKET
;
106 ch
.header
.cmsg_type
= SCM_RIGHTS
;
107 ch
.header
.cmsg_len
= sizeof(ch
);
109 *(int *)CMSG_DATA(&ch
.header
) = sockets
[1];
110 sendmsg(ipvi
->ofd
, &mh
, 0);
111 dummy
= (fd
== -1) ? ' ' : 'F';
112 *(int *)CMSG_DATA(&ch
.header
) = sockets
[1];
113 sendmsg(sockets
[0], &mh
, 0);
117 *(int *)CMSG_DATA(&ch
.header
) = fd
;
118 sendmsg(sockets
[0], &mh
, 0);
122 ipviwin
->ifd
= sockets
[0];
123 ipviwin
->ofd
= sockets
[0];
126 #define IPVISET(func) \
127 ipviwin->func = vi_##func;
147 ipviwin
->close
= vi_win_close
;
159 vi_set_ops(IPVIWIN
*ipvi
, IPSIOPS
*ops
)
165 static int vi_close(IPVI
*ipvi
)
167 memset(ipvi
, 6, sizeof(IPVI
));
172 static int vi_win_close(IPVIWIN
*ipviwin
)
174 memset(ipviwin
, 6, sizeof(IPVIWIN
));
181 vi_send_(IPVIWIN
*ipvi
, int code
)
185 return vi_send(ipvi
->ofd
, NULL
, &ipb
);
189 vi_send_1(IPVIWIN
*ipvi
, int code
, u_int32_t val
)
194 return vi_send(ipvi
->ofd
, "1", &ipb
);
198 vi_send_12(IPVIWIN
*ipvi
, int code
, u_int32_t val1
, u_int32_t val2
)
205 return vi_send(ipvi
->ofd
, "12", &ipb
);
209 vi_send_a(IPVIWIN
*ipvi
, int code
, const char *str
, u_int32_t len
)
216 return vi_send(ipvi
->ofd
, "a", &ipb
);
220 vi_send_a1(IPVIWIN
*ipvi
, int code
, const char *str
, u_int32_t len
,
229 return vi_send(ipvi
->ofd
, "a1", &ipb
);
233 vi_send_ab1(IPVIWIN
*ipvi
, int code
, const char *str1
, u_int32_t len1
,
234 const char *str2
, u_int32_t len2
, u_int32_t val
)
244 return vi_send(ipvi
->ofd
, "ab1", &ipb
);