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