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