1 #include	"unpxti.h"
2 
3 int
xti_setopt(int fd,int level,int name,void * optval,socklen_t optlen)4 xti_setopt(int fd, int level, int name, void *optval, socklen_t optlen)
5 {
6 	int					rc;
7 	struct t_optmgmt	*req, *ret;
8 	struct t_opthdr		*topt;
9 
10 	req = T_alloc(fd, T_OPTMGMT, T_ALL);
11 	ret = T_alloc(fd, T_OPTMGMT, T_ALL);
12 	if (req->opt.maxlen == 0)
13 		err_quit("xti_setopt: req.opt.maxlen == 0");
14 
15 	topt = (struct t_opthdr *) req->opt.buf;
16 	topt->level = level;
17 	topt->name = name;
18 	topt->len = sizeof(struct t_opthdr) + optlen;
19 	if (topt->len > req->opt.maxlen)
20 		err_quit("optlen too big");
21 	req->opt.len = topt->len;
22 	memcpy(topt+1, optval, optlen);	/* copy option value */
23 
24 	req->flags = T_NEGOTIATE;
25 	if (t_optmgmt(fd, req, ret) < 0) {
26 		T_free(req, T_OPTMGMT);
27 		T_free(ret, T_OPTMGMT);
28 		return(-1);
29 	}
30 	rc = ret->flags;
31 
32 	T_free(req, T_OPTMGMT);
33 	T_free(ret, T_OPTMGMT);
34 
35 	if (rc == T_SUCCESS || rc == T_PARTSUCCESS)
36 		return(0);
37 	return(-1);		/* T_FAILURE, T_NOTSUPPORT, T_READONLY */
38 }
39