xref: /csrg-svn/contrib/connectd/cd/snd.c (revision 60591)
1*60591Sbostic /*-
2*60591Sbostic  * Copyright (c) 1993 The Regents of the University of California.
338018Sbostic  * All rights reserved.
438018Sbostic  *
538018Sbostic  * This code is derived from software contributed to Berkeley by
638018Sbostic  * Bill Jolitz.
738018Sbostic  *
8*60591Sbostic  * %sccs.include.redist.c%
938018Sbostic  */
1038018Sbostic 
1138018Sbostic #ifndef lint
12*60591Sbostic static char sccsid[] = "@(#)snd.c	5.2 (Berkeley) 05/29/93";
1338018Sbostic #endif /* not lint */
1438018Sbostic 
1538018Sbostic #include "main.h"
1638018Sbostic 
1738018Sbostic /*
1838018Sbostic  * Send a message back to a customer,
1938018Sbostic  * from data structures and return error status
2038018Sbostic  */
2138018Sbostic int
sendrequest(sock,rqst,cp,opts,optlen,fd)2238018Sbostic sendrequest(sock, rqst, cp, opts, optlen, fd)
2338018Sbostic 	int sock, rqst ;
2438018Sbostic 	struct conversation *cp ;
2538018Sbostic 	char *opts;
2638018Sbostic 	int optlen, fd ;
2738018Sbostic {
2838018Sbostic 	int rv ;
2938018Sbostic 	struct iovec iov[4];
3038018Sbostic 	struct msghdr msg ;
3138018Sbostic 
3238018Sbostic 	/* send message to user application containing fd */
3338018Sbostic 	msg.msg_name = "" ;
3438018Sbostic 	msg.msg_namelen = 0 ;		/* size of address */
3538018Sbostic 	iov[0].iov_base = (caddr_t) &rqst ;
3638018Sbostic 	iov[0].iov_len = sizeof (rqst) ;
3738018Sbostic 	iov[1].iov_base = (caddr_t) &cp->co_constatus ;
3838018Sbostic 	iov[1].iov_len = sizeof(int) ;
3938018Sbostic 	msg.msg_iov = iov;
4038018Sbostic 	msg.msg_iovlen = 2;
4138018Sbostic 	if (opts) {
4238018Sbostic 		iov[2].iov_base = (caddr_t) opts;
4338018Sbostic 		iov[2].iov_len = optlen ;
4438018Sbostic 		msg.msg_iovlen = 3;
4538018Sbostic 	}
4638018Sbostic 	if (fd >= 0) {
4738018Sbostic 		msg.msg_accrights = (caddr_t) &fd ;
4838018Sbostic 		msg.msg_accrightslen = sizeof(int) ;
4938018Sbostic 	} else	{
5038018Sbostic 		msg.msg_accrightslen = 0 ;
5138018Sbostic 		msg.msg_accrights = 0 ;
5238018Sbostic 	}
5338018Sbostic 
5438018Sbostic 	rv = sendmsg(sock, &msg, 0) ;
5538018Sbostic 	if (rv < 0) {
5638018Sbostic 		perror("snd:") ;
5738018Sbostic 	}
5838018Sbostic 	return (rv) ;
5938018Sbostic }
60