xref: /csrg-svn/contrib/connectd/cd/snd.c (revision 38018)
1*38018Sbostic /*
2*38018Sbostic  * Copyright (c) 1989 The Regents of the University of California.
3*38018Sbostic  * All rights reserved.
4*38018Sbostic  *
5*38018Sbostic  * This code is derived from software contributed to Berkeley by
6*38018Sbostic  * Bill Jolitz.
7*38018Sbostic  *
8*38018Sbostic  * Redistribution and use in source and binary forms are permitted
9*38018Sbostic  * provided that the above copyright notice and this paragraph are
10*38018Sbostic  * duplicated in all such forms and that any documentation,
11*38018Sbostic  * advertising materials, and other materials related to such
12*38018Sbostic  * distribution and use acknowledge that the software was developed
13*38018Sbostic  * by the University of California, Berkeley.  The name of the
14*38018Sbostic  * University may not be used to endorse or promote products derived
15*38018Sbostic  * from this software without specific prior written permission.
16*38018Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17*38018Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18*38018Sbostic  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19*38018Sbostic  */
20*38018Sbostic 
21*38018Sbostic #ifndef lint
22*38018Sbostic static char sccsid[] = "@(#)snd.c	5.1 (Berkeley) 05/16/89";
23*38018Sbostic #endif /* not lint */
24*38018Sbostic 
25*38018Sbostic #include "main.h"
26*38018Sbostic 
27*38018Sbostic /*
28*38018Sbostic  * Send a message back to a customer,
29*38018Sbostic  * from data structures and return error status
30*38018Sbostic  */
31*38018Sbostic int
32*38018Sbostic sendrequest(sock, rqst, cp, opts, optlen, fd)
33*38018Sbostic 	int sock, rqst ;
34*38018Sbostic 	struct conversation *cp ;
35*38018Sbostic 	char *opts;
36*38018Sbostic 	int optlen, fd ;
37*38018Sbostic {
38*38018Sbostic 	int rv ;
39*38018Sbostic 	struct iovec iov[4];
40*38018Sbostic 	struct msghdr msg ;
41*38018Sbostic 
42*38018Sbostic 	/* send message to user application containing fd */
43*38018Sbostic 	msg.msg_name = "" ;
44*38018Sbostic 	msg.msg_namelen = 0 ;		/* size of address */
45*38018Sbostic 	iov[0].iov_base = (caddr_t) &rqst ;
46*38018Sbostic 	iov[0].iov_len = sizeof (rqst) ;
47*38018Sbostic 	iov[1].iov_base = (caddr_t) &cp->co_constatus ;
48*38018Sbostic 	iov[1].iov_len = sizeof(int) ;
49*38018Sbostic 	msg.msg_iov = iov;
50*38018Sbostic 	msg.msg_iovlen = 2;
51*38018Sbostic 	if (opts) {
52*38018Sbostic 		iov[2].iov_base = (caddr_t) opts;
53*38018Sbostic 		iov[2].iov_len = optlen ;
54*38018Sbostic 		msg.msg_iovlen = 3;
55*38018Sbostic 	}
56*38018Sbostic 	if (fd >= 0) {
57*38018Sbostic 		msg.msg_accrights = (caddr_t) &fd ;
58*38018Sbostic 		msg.msg_accrightslen = sizeof(int) ;
59*38018Sbostic 	} else	{
60*38018Sbostic 		msg.msg_accrightslen = 0 ;
61*38018Sbostic 		msg.msg_accrights = 0 ;
62*38018Sbostic 	}
63*38018Sbostic 
64*38018Sbostic 	rv = sendmsg(sock, &msg, 0) ;
65*38018Sbostic 	if (rv < 0) {
66*38018Sbostic 		perror("snd:") ;
67*38018Sbostic 	}
68*38018Sbostic 	return (rv) ;
69*38018Sbostic }
70