xref: /original-bsd/contrib/connectd/cd/rcv.c (revision e4fa375e)
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[] = "@(#)rcv.c	5.2 (Berkeley) 05/29/93";
13 #endif /* not lint */
14 
15 #include "main.h"
16 
17 /*
18  * Recieve a message from a customer,
19  * put in data structures and return message request type
20  */
21 int
22 rcvrequest(sock, cp, opts, optlen, rfdp)
23 	int sock ;
24 	struct conversation *cp ;
25 	char **opts;
26 	int *optlen, *rfdp ;
27 
28 {
29 	int rv ;
30 	struct iovec iov[4];
31 	int rqstfmt;
32 	struct msghdr msg ;
33 	struct connectdomain *cdp;
34 
35 	cdp = &cp->co_cd ;
36 	msg.msg_name = "";		/* optional address */
37 	msg.msg_namelen = 0 ;		/* size of address */
38 	iov[0].iov_base = (caddr_t) &rqstfmt ;
39 	iov[0].iov_len = sizeof (rqstfmt) ;
40 	iov[1].iov_base = (caddr_t) cdp ;
41 	iov[1].iov_len = sizeof(cp->co_optionsbuf) + sizeof (cp->co_cd) ;
42 	msg.msg_iov = iov;
43 	msg.msg_iovlen = 2;
44 	msg.msg_accrights = (caddr_t) rfdp ;
45 	msg.msg_accrightslen = 4;
46 
47 	if ((rv = recvmsg (sock, &msg, 0)) <= 0 ) {
48 		perror("connection request message recieve") ;
49 		return (-1) ;
50 	}
51 
52 	if (iov[1].iov_len > CDSIZE(cdp))  {
53 		*optlen = iov[1].iov_len - CDSIZE(cdp) ;
54 		*opts = iov[1].iov_base + CDSIZE(cdp);
55 	} else	*optlen = 0 ;
56 
57 	if (msg.msg_accrightslen != 4) *rfdp = -1 ;
58 
59 	return (rqstfmt) ;
60 }
61