3 * Rob Zimmermann. All rights reserved.
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
12 #include <sys/types.h>
13 #include <sys/queue.h>
16 #include <bitstring.h>
26 #include "../common/common.h"
29 static int vi_send_
__P((IPVIWIN
*, int));
30 static int vi_send_1
__P((IPVIWIN
*, int, u_int32_t
));
31 static int vi_send_12
__P((IPVIWIN
*ipvi
, int code
, u_int32_t val1
, u_int32_t val2
));
32 static int vi_send_ab1
__P((IPVIWIN
*ipvi
, int code
,
33 const char *str1
, u_int32_t len1
,
34 const char *str2
, u_int32_t len2
, u_int32_t val
));
35 static int vi_send_a1
__P((IPVIWIN
*ipvi
, int code
, const char *str
, u_int32_t len
,
37 static int vi_send_a
__P((IPVIWIN
*ipvi
, int code
, const char *str
, u_int32_t len
));
41 static int vi_set_ops
__P((IPVIWIN
*, IPSIOPS
*));
42 static int vi_win_close
__P((IPVIWIN
*));
44 static int vi_close
__P((IPVI
*));
45 static int vi_new_window
__P((IPVI
*, IPVIWIN
**, int));
50 * PUBLIC: int vi_create __P((IPVI **, u_int32_t));
53 vi_create(IPVI
**ipvip
, u_int32_t flags
)
57 MALLOC_GOTO(NULL
, ipvi
, IPVI
*, sizeof(IPVI
));
58 memset(ipvi
, 0, sizeof(IPVI
));
63 ipvi
->new_window
= vi_new_window
;
64 ipvi
->close
= vi_close
;
75 vi_new_window (IPVI
*ipvi
, IPVIWIN
**ipviwinp
, int fd
)
79 MALLOC_GOTO(NULL
, ipviwin
, IPVIWIN
*, sizeof(IPVIWIN
));
80 memset(ipviwin
, 0, sizeof(IPVIWIN
));
83 ipviwin
->ifd
= ipvi
->ifd
;
84 ipviwin
->ofd
= ipvi
->ofd
;
92 socketpair(AF_LOCAL
, SOCK_STREAM
, 0, sockets
);
97 mh
.msg_controllen
= sizeof(ch
);
98 mh
.msg_control
= (void *)&ch
;
101 iov
.iov_base
= &dummy
;
103 ch
.header
.cmsg_level
= SOL_SOCKET
;
104 ch
.header
.cmsg_type
= SCM_RIGHTS
;
105 ch
.header
.cmsg_len
= sizeof(ch
);
107 *(int *)CMSG_DATA(&ch
.header
) = sockets
[1];
108 sendmsg(ipvi
->ofd
, &mh
, 0);
109 dummy
= (fd
== -1) ? ' ' : 'F';
110 *(int *)CMSG_DATA(&ch
.header
) = sockets
[1];
111 sendmsg(sockets
[0], &mh
, 0);
115 *(int *)CMSG_DATA(&ch
.header
) = fd
;
116 sendmsg(sockets
[0], &mh
, 0);
120 ipviwin
->ifd
= sockets
[0];
121 ipviwin
->ofd
= sockets
[0];
124 #define IPVISET(func) \
125 ipviwin->func = vi_##func;
145 ipviwin
->close
= vi_win_close
;
157 vi_set_ops(IPVIWIN
*ipvi
, IPSIOPS
*ops
)
163 static int vi_close(IPVI
*ipvi
)
165 memset(ipvi
, 6, sizeof(IPVI
));
170 static int vi_win_close(IPVIWIN
*ipviwin
)
172 memset(ipviwin
, 6, sizeof(IPVIWIN
));
179 vi_send_(IPVIWIN
*ipvi
, int code
)
183 return vi_send(ipvi
->ofd
, NULL
, &ipb
);
187 vi_send_1(IPVIWIN
*ipvi
, int code
, u_int32_t val
)
192 return vi_send(ipvi
->ofd
, "1", &ipb
);
196 vi_send_12(IPVIWIN
*ipvi
, int code
, u_int32_t val1
, u_int32_t val2
)
203 return vi_send(ipvi
->ofd
, "12", &ipb
);
207 vi_send_a(IPVIWIN
*ipvi
, int code
, const char *str
, u_int32_t len
)
214 return vi_send(ipvi
->ofd
, "a", &ipb
);
218 vi_send_a1(IPVIWIN
*ipvi
, int code
, const char *str
, u_int32_t len
,
227 return vi_send(ipvi
->ofd
, "a1", &ipb
);
231 vi_send_ab1(IPVIWIN
*ipvi
, int code
, const char *str1
, u_int32_t len1
,
232 const char *str2
, u_int32_t len2
, u_int32_t val
)
242 return vi_send(ipvi
->ofd
, "ab1", &ipb
);