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[] = "@(#)snd.c 5.1 (Berkeley) 05/16/89"; 23 #endif /* not lint */ 24 25 #include "main.h" 26 27 /* 28 * Send a message back to a customer, 29 * from data structures and return error status 30 */ 31 int 32 sendrequest(sock, rqst, cp, opts, optlen, fd) 33 int sock, rqst ; 34 struct conversation *cp ; 35 char *opts; 36 int optlen, fd ; 37 { 38 int rv ; 39 struct iovec iov[4]; 40 struct msghdr msg ; 41 42 /* send message to user application containing fd */ 43 msg.msg_name = "" ; 44 msg.msg_namelen = 0 ; /* size of address */ 45 iov[0].iov_base = (caddr_t) &rqst ; 46 iov[0].iov_len = sizeof (rqst) ; 47 iov[1].iov_base = (caddr_t) &cp->co_constatus ; 48 iov[1].iov_len = sizeof(int) ; 49 msg.msg_iov = iov; 50 msg.msg_iovlen = 2; 51 if (opts) { 52 iov[2].iov_base = (caddr_t) opts; 53 iov[2].iov_len = optlen ; 54 msg.msg_iovlen = 3; 55 } 56 if (fd >= 0) { 57 msg.msg_accrights = (caddr_t) &fd ; 58 msg.msg_accrightslen = sizeof(int) ; 59 } else { 60 msg.msg_accrightslen = 0 ; 61 msg.msg_accrights = 0 ; 62 } 63 64 rv = sendmsg(sock, &msg, 0) ; 65 if (rv < 0) { 66 perror("snd:") ; 67 } 68 return (rv) ; 69 } 70