1 /* $NetBSD: sendmsg.c,v 1.1.1.2 2014/04/24 12:45:52 pettai Exp $ */
4 * Copyright (c) 1995, 1996, 1997, 1998, 1999 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include <krb5/roken.h>
42 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
43 sendmsg(rk_socket_t s
, const struct msghdr
*msg
, int flags
)
49 struct iovec
*iov
= msg
->msg_iov
;
51 for(i
= 0; i
< msg
->msg_iovlen
; ++i
)
52 tot
+= iov
[i
].iov_len
;
54 if (tot
!= 0 && buf
== NULL
) {
59 for (i
= 0; i
< msg
->msg_iovlen
; ++i
) {
60 memcpy (p
, iov
[i
].iov_base
, iov
[i
].iov_len
);
63 ret
= sendto (s
, buf
, tot
, flags
, msg
->msg_name
, msg
->msg_namelen
);
70 /***********************************************************************
71 * Copyright (c) 2009, Secure Endpoints Inc.
72 * All rights reserved.
74 * Redistribution and use in source and binary forms, with or without
75 * modification, are permitted provided that the following conditions
78 * - Redistributions of source code must retain the above copyright
79 * notice, this list of conditions and the following disclaimer.
81 * - Redistributions in binary form must reproduce the above copyright
82 * notice, this list of conditions and the following disclaimer in
83 * the documentation and/or other materials provided with the
86 * - Neither the name of Secure Endpoints Inc. nor the names of its
87 * contributors may be used to endorse or promote products derived
88 * from this software without specific prior written permission.
90 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
91 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
92 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
93 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
94 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
95 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
96 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
97 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
98 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
99 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
100 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
101 * OF THE POSSIBILITY OF SUCH DAMAGE.
103 **********************************************************************/
106 * Implementation of sendmsg() for WIN32
108 * We are using a contrived definition of msghdr which actually uses
109 * an array of ::_WSABUF structures instead of ::iovec . This allows
110 * us to call WSASend directly using the given ::msghdr instead of
111 * having to allocate another array of ::_WSABUF and copying data for
116 * - msg->msg_name is ignored. So is msg->control.
117 * - WSASend() only supports ::MSG_DONTROUTE, ::MSG_OOB and
120 * @param[in] s The socket to use.
121 * @param[in] msg The message
122 * @param[in] flags Flags. A combination of ::MSG_DONTROUTE,
123 * ::MSG_OOB and ::MSG_PARTIAL
125 * @return The number of bytes sent, on success. Or -1 on error.
127 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
128 sendmsg_w32(rk_socket_t s
, const struct msghdr
* msg
, int flags
)
131 DWORD num_bytes_sent
= 0;
133 /* TODO: For _WIN32_WINNT >= 0x0600 we can use WSASendMsg using
134 WSAMSG which is a much more direct analogue to sendmsg(). */
136 srv
= WSASend(s
, msg
->msg_iov
, msg
->msg_iovlen
,
137 &num_bytes_sent
, flags
, NULL
, NULL
);
140 return (int) num_bytes_sent
;
142 /* srv == SOCKET_ERROR and WSAGetLastError() == WSA_IO_PENDING
143 indicates that a non-blocking transfer has been scheduled.
144 We'll have to check for that if we ever support non-blocking