1*60591Sbostic /*-
2*60591Sbostic * Copyright (c) 1993 The Regents of the University of California.
338017Sbostic * All rights reserved.
438017Sbostic *
538017Sbostic * This code is derived from software contributed to Berkeley by
638017Sbostic * Bill Jolitz.
738017Sbostic *
8*60591Sbostic * %sccs.include.redist.c%
938017Sbostic */
1038017Sbostic
1138017Sbostic #ifndef lint
12*60591Sbostic static char sccsid[] = "@(#)rcv.c 5.2 (Berkeley) 05/29/93";
1338017Sbostic #endif /* not lint */
1438017Sbostic
1538017Sbostic #include "main.h"
1638017Sbostic
1738017Sbostic /*
1838017Sbostic * Recieve a message from a customer,
1938017Sbostic * put in data structures and return message request type
2038017Sbostic */
2138017Sbostic int
rcvrequest(sock,cp,opts,optlen,rfdp)2238017Sbostic rcvrequest(sock, cp, opts, optlen, rfdp)
2338017Sbostic int sock ;
2438017Sbostic struct conversation *cp ;
2538017Sbostic char **opts;
2638017Sbostic int *optlen, *rfdp ;
2738017Sbostic
2838017Sbostic {
2938017Sbostic int rv ;
3038017Sbostic struct iovec iov[4];
3138017Sbostic int rqstfmt;
3238017Sbostic struct msghdr msg ;
3338017Sbostic struct connectdomain *cdp;
3438017Sbostic
3538017Sbostic cdp = &cp->co_cd ;
3638017Sbostic msg.msg_name = ""; /* optional address */
3738017Sbostic msg.msg_namelen = 0 ; /* size of address */
3838017Sbostic iov[0].iov_base = (caddr_t) &rqstfmt ;
3938017Sbostic iov[0].iov_len = sizeof (rqstfmt) ;
4038017Sbostic iov[1].iov_base = (caddr_t) cdp ;
4138017Sbostic iov[1].iov_len = sizeof(cp->co_optionsbuf) + sizeof (cp->co_cd) ;
4238017Sbostic msg.msg_iov = iov;
4338017Sbostic msg.msg_iovlen = 2;
4438017Sbostic msg.msg_accrights = (caddr_t) rfdp ;
4538017Sbostic msg.msg_accrightslen = 4;
4638017Sbostic
4738017Sbostic if ((rv = recvmsg (sock, &msg, 0)) <= 0 ) {
4838017Sbostic perror("connection request message recieve") ;
4938017Sbostic return (-1) ;
5038017Sbostic }
5138017Sbostic
5238017Sbostic if (iov[1].iov_len > CDSIZE(cdp)) {
5338017Sbostic *optlen = iov[1].iov_len - CDSIZE(cdp) ;
5438017Sbostic *opts = iov[1].iov_base + CDSIZE(cdp);
5538017Sbostic } else *optlen = 0 ;
5638017Sbostic
5738017Sbostic if (msg.msg_accrightslen != 4) *rfdp = -1 ;
5838017Sbostic
5938017Sbostic return (rqstfmt) ;
6038017Sbostic }
61