xref: /original-bsd/contrib/connectd/cd/snd.c (revision 70c286c1)
1 /*-
2  * Copyright (c) 1993 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Bill Jolitz.
7  *
8  * %sccs.include.redist.c%
9  */
10 
11 #ifndef lint
12 static char sccsid[] = "@(#)snd.c	5.2 (Berkeley) 05/29/93";
13 #endif /* not lint */
14 
15 #include "main.h"
16 
17 /*
18  * Send a message back to a customer,
19  * from data structures and return error status
20  */
21 int
sendrequest(sock,rqst,cp,opts,optlen,fd)22 sendrequest(sock, rqst, cp, opts, optlen, fd)
23 	int sock, rqst ;
24 	struct conversation *cp ;
25 	char *opts;
26 	int optlen, fd ;
27 {
28 	int rv ;
29 	struct iovec iov[4];
30 	struct msghdr msg ;
31 
32 	/* send message to user application containing fd */
33 	msg.msg_name = "" ;
34 	msg.msg_namelen = 0 ;		/* size of address */
35 	iov[0].iov_base = (caddr_t) &rqst ;
36 	iov[0].iov_len = sizeof (rqst) ;
37 	iov[1].iov_base = (caddr_t) &cp->co_constatus ;
38 	iov[1].iov_len = sizeof(int) ;
39 	msg.msg_iov = iov;
40 	msg.msg_iovlen = 2;
41 	if (opts) {
42 		iov[2].iov_base = (caddr_t) opts;
43 		iov[2].iov_len = optlen ;
44 		msg.msg_iovlen = 3;
45 	}
46 	if (fd >= 0) {
47 		msg.msg_accrights = (caddr_t) &fd ;
48 		msg.msg_accrightslen = sizeof(int) ;
49 	} else	{
50 		msg.msg_accrightslen = 0 ;
51 		msg.msg_accrights = 0 ;
52 	}
53 
54 	rv = sendmsg(sock, &msg, 0) ;
55 	if (rv < 0) {
56 		perror("snd:") ;
57 	}
58 	return (rv) ;
59 }
60