1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate #define _XPG4_2
30*7c478bd9Sstevel@tonic-gate #define __EXTENSIONS__
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gate #include <assert.h>
33*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/uio.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/socket.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
37*7c478bd9Sstevel@tonic-gate #include <sys/stream.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/socketvar.h>
39*7c478bd9Sstevel@tonic-gate #include <sys/sockio.h>
40*7c478bd9Sstevel@tonic-gate
41*7c478bd9Sstevel@tonic-gate #include <errno.h>
42*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
43*7c478bd9Sstevel@tonic-gate #include <unistd.h>
44*7c478bd9Sstevel@tonic-gate #include <stropts.h>
45*7c478bd9Sstevel@tonic-gate #include <stdio.h>
46*7c478bd9Sstevel@tonic-gate #include <strings.h>
47*7c478bd9Sstevel@tonic-gate #include <netinet/in.h>
48*7c478bd9Sstevel@tonic-gate #include <netinet/sctp.h>
49*7c478bd9Sstevel@tonic-gate
50*7c478bd9Sstevel@tonic-gate /* This will hold either a v4 or a v6 sockaddr */
51*7c478bd9Sstevel@tonic-gate union sockaddr_storage_v6 {
52*7c478bd9Sstevel@tonic-gate struct sockaddr_in in;
53*7c478bd9Sstevel@tonic-gate struct sockaddr_in6 in6;
54*7c478bd9Sstevel@tonic-gate };
55*7c478bd9Sstevel@tonic-gate
56*7c478bd9Sstevel@tonic-gate /*
57*7c478bd9Sstevel@tonic-gate * This file implements all the libsctp calls.
58*7c478bd9Sstevel@tonic-gate */
59*7c478bd9Sstevel@tonic-gate
60*7c478bd9Sstevel@tonic-gate /*
61*7c478bd9Sstevel@tonic-gate * To bind a list of addresses to a socket. If the socket is
62*7c478bd9Sstevel@tonic-gate * v4, the type of the list of addresses is (struct in_addr).
63*7c478bd9Sstevel@tonic-gate * If the socket is v6, the type is (struct in6_addr).
64*7c478bd9Sstevel@tonic-gate */
65*7c478bd9Sstevel@tonic-gate int
sctp_bindx(int sock,void * addrs,int addrcnt,int flags)66*7c478bd9Sstevel@tonic-gate sctp_bindx(int sock, void *addrs, int addrcnt, int flags)
67*7c478bd9Sstevel@tonic-gate {
68*7c478bd9Sstevel@tonic-gate socklen_t sz;
69*7c478bd9Sstevel@tonic-gate
70*7c478bd9Sstevel@tonic-gate if (addrs == NULL || addrcnt == 0) {
71*7c478bd9Sstevel@tonic-gate errno = EINVAL;
72*7c478bd9Sstevel@tonic-gate return (-1);
73*7c478bd9Sstevel@tonic-gate }
74*7c478bd9Sstevel@tonic-gate
75*7c478bd9Sstevel@tonic-gate /* Assume the caller uses the correct family type. */
76*7c478bd9Sstevel@tonic-gate switch (((struct sockaddr *)addrs)->sa_family) {
77*7c478bd9Sstevel@tonic-gate case AF_INET:
78*7c478bd9Sstevel@tonic-gate sz = sizeof (struct sockaddr_in);
79*7c478bd9Sstevel@tonic-gate break;
80*7c478bd9Sstevel@tonic-gate case AF_INET6:
81*7c478bd9Sstevel@tonic-gate sz = sizeof (struct sockaddr_in6);
82*7c478bd9Sstevel@tonic-gate break;
83*7c478bd9Sstevel@tonic-gate default:
84*7c478bd9Sstevel@tonic-gate errno = EAFNOSUPPORT;
85*7c478bd9Sstevel@tonic-gate return (-1);
86*7c478bd9Sstevel@tonic-gate }
87*7c478bd9Sstevel@tonic-gate
88*7c478bd9Sstevel@tonic-gate switch (flags) {
89*7c478bd9Sstevel@tonic-gate case SCTP_BINDX_ADD_ADDR:
90*7c478bd9Sstevel@tonic-gate return (setsockopt(sock, IPPROTO_SCTP, SCTP_ADD_ADDR, addrs,
91*7c478bd9Sstevel@tonic-gate sz * addrcnt));
92*7c478bd9Sstevel@tonic-gate case SCTP_BINDX_REM_ADDR:
93*7c478bd9Sstevel@tonic-gate return (setsockopt(sock, IPPROTO_SCTP, SCTP_REM_ADDR, addrs,
94*7c478bd9Sstevel@tonic-gate sz * addrcnt));
95*7c478bd9Sstevel@tonic-gate default:
96*7c478bd9Sstevel@tonic-gate errno = EINVAL;
97*7c478bd9Sstevel@tonic-gate return (-1);
98*7c478bd9Sstevel@tonic-gate }
99*7c478bd9Sstevel@tonic-gate }
100*7c478bd9Sstevel@tonic-gate
101*7c478bd9Sstevel@tonic-gate /*
102*7c478bd9Sstevel@tonic-gate * XXX currently not atomic -- need a better way to do this.
103*7c478bd9Sstevel@tonic-gate */
104*7c478bd9Sstevel@tonic-gate int
sctp_getpaddrs(int sock,sctp_assoc_t id,void ** addrs)105*7c478bd9Sstevel@tonic-gate sctp_getpaddrs(int sock, sctp_assoc_t id, void **addrs)
106*7c478bd9Sstevel@tonic-gate {
107*7c478bd9Sstevel@tonic-gate uint32_t naddrs;
108*7c478bd9Sstevel@tonic-gate socklen_t bufsz;
109*7c478bd9Sstevel@tonic-gate struct sctpopt opt;
110*7c478bd9Sstevel@tonic-gate
111*7c478bd9Sstevel@tonic-gate if (addrs == NULL) {
112*7c478bd9Sstevel@tonic-gate errno = EINVAL;
113*7c478bd9Sstevel@tonic-gate return (-1);
114*7c478bd9Sstevel@tonic-gate }
115*7c478bd9Sstevel@tonic-gate
116*7c478bd9Sstevel@tonic-gate /* First, find out how many peer addresses there are. */
117*7c478bd9Sstevel@tonic-gate *addrs = NULL;
118*7c478bd9Sstevel@tonic-gate
119*7c478bd9Sstevel@tonic-gate opt.sopt_aid = id;
120*7c478bd9Sstevel@tonic-gate opt.sopt_name = SCTP_GET_NPADDRS;
121*7c478bd9Sstevel@tonic-gate opt.sopt_val = (caddr_t)&naddrs;
122*7c478bd9Sstevel@tonic-gate opt.sopt_len = sizeof (naddrs);
123*7c478bd9Sstevel@tonic-gate if (ioctl(sock, SIOCSCTPGOPT, &opt) == -1) {
124*7c478bd9Sstevel@tonic-gate return (-1);
125*7c478bd9Sstevel@tonic-gate }
126*7c478bd9Sstevel@tonic-gate if (naddrs == 0)
127*7c478bd9Sstevel@tonic-gate return (0);
128*7c478bd9Sstevel@tonic-gate
129*7c478bd9Sstevel@tonic-gate /*
130*7c478bd9Sstevel@tonic-gate * Now we can get all the peer addresses. This will over allocate
131*7c478bd9Sstevel@tonic-gate * space for v4 socket. But it should be OK and save us
132*7c478bd9Sstevel@tonic-gate * the job to find out if it is a v4 or v6 socket.
133*7c478bd9Sstevel@tonic-gate */
134*7c478bd9Sstevel@tonic-gate bufsz = sizeof (union sockaddr_storage_v6) * naddrs;
135*7c478bd9Sstevel@tonic-gate if ((*addrs = malloc(bufsz)) == NULL) {
136*7c478bd9Sstevel@tonic-gate return (-1);
137*7c478bd9Sstevel@tonic-gate }
138*7c478bd9Sstevel@tonic-gate opt.sopt_name = SCTP_GET_PADDRS;
139*7c478bd9Sstevel@tonic-gate opt.sopt_val = *addrs;
140*7c478bd9Sstevel@tonic-gate opt.sopt_len = bufsz;
141*7c478bd9Sstevel@tonic-gate if (ioctl(sock, SIOCSCTPGOPT, &opt) == -1) {
142*7c478bd9Sstevel@tonic-gate free(*addrs);
143*7c478bd9Sstevel@tonic-gate *addrs = NULL;
144*7c478bd9Sstevel@tonic-gate return (-1);
145*7c478bd9Sstevel@tonic-gate }
146*7c478bd9Sstevel@tonic-gate
147*7c478bd9Sstevel@tonic-gate /* Calculate the number of addresses returned. */
148*7c478bd9Sstevel@tonic-gate switch (((struct sockaddr *)*addrs)->sa_family) {
149*7c478bd9Sstevel@tonic-gate case AF_INET:
150*7c478bd9Sstevel@tonic-gate naddrs = opt.sopt_len / sizeof (struct sockaddr_in);
151*7c478bd9Sstevel@tonic-gate break;
152*7c478bd9Sstevel@tonic-gate case AF_INET6:
153*7c478bd9Sstevel@tonic-gate naddrs = opt.sopt_len / sizeof (struct sockaddr_in6);
154*7c478bd9Sstevel@tonic-gate break;
155*7c478bd9Sstevel@tonic-gate }
156*7c478bd9Sstevel@tonic-gate return (naddrs);
157*7c478bd9Sstevel@tonic-gate }
158*7c478bd9Sstevel@tonic-gate
159*7c478bd9Sstevel@tonic-gate void
sctp_freepaddrs(void * addrs)160*7c478bd9Sstevel@tonic-gate sctp_freepaddrs(void *addrs)
161*7c478bd9Sstevel@tonic-gate {
162*7c478bd9Sstevel@tonic-gate free(addrs);
163*7c478bd9Sstevel@tonic-gate }
164*7c478bd9Sstevel@tonic-gate
165*7c478bd9Sstevel@tonic-gate int
sctp_getladdrs(int sock,sctp_assoc_t id,void ** addrs)166*7c478bd9Sstevel@tonic-gate sctp_getladdrs(int sock, sctp_assoc_t id, void **addrs)
167*7c478bd9Sstevel@tonic-gate {
168*7c478bd9Sstevel@tonic-gate uint32_t naddrs;
169*7c478bd9Sstevel@tonic-gate socklen_t bufsz;
170*7c478bd9Sstevel@tonic-gate struct sctpopt opt;
171*7c478bd9Sstevel@tonic-gate
172*7c478bd9Sstevel@tonic-gate if (addrs == NULL) {
173*7c478bd9Sstevel@tonic-gate errno = EINVAL;
174*7c478bd9Sstevel@tonic-gate return (-1);
175*7c478bd9Sstevel@tonic-gate }
176*7c478bd9Sstevel@tonic-gate
177*7c478bd9Sstevel@tonic-gate /* First, try to find out how many bound addresses there are. */
178*7c478bd9Sstevel@tonic-gate *addrs = NULL;
179*7c478bd9Sstevel@tonic-gate
180*7c478bd9Sstevel@tonic-gate opt.sopt_aid = id;
181*7c478bd9Sstevel@tonic-gate opt.sopt_name = SCTP_GET_NLADDRS;
182*7c478bd9Sstevel@tonic-gate opt.sopt_val = (caddr_t)&naddrs;
183*7c478bd9Sstevel@tonic-gate opt.sopt_len = sizeof (naddrs);
184*7c478bd9Sstevel@tonic-gate if (ioctl(sock, SIOCSCTPGOPT, &opt) == -1) {
185*7c478bd9Sstevel@tonic-gate return (-1);
186*7c478bd9Sstevel@tonic-gate }
187*7c478bd9Sstevel@tonic-gate if (naddrs == 0)
188*7c478bd9Sstevel@tonic-gate return (0);
189*7c478bd9Sstevel@tonic-gate
190*7c478bd9Sstevel@tonic-gate /*
191*7c478bd9Sstevel@tonic-gate * Now we can get all the bound addresses. This will over allocate
192*7c478bd9Sstevel@tonic-gate * space for v4 socket. But it should be OK and save us
193*7c478bd9Sstevel@tonic-gate * the job to find out if it is a v4 or v6 socket.
194*7c478bd9Sstevel@tonic-gate */
195*7c478bd9Sstevel@tonic-gate bufsz = sizeof (union sockaddr_storage_v6) * naddrs;
196*7c478bd9Sstevel@tonic-gate if ((*addrs = malloc(bufsz)) == NULL) {
197*7c478bd9Sstevel@tonic-gate return (-1);
198*7c478bd9Sstevel@tonic-gate }
199*7c478bd9Sstevel@tonic-gate opt.sopt_name = SCTP_GET_LADDRS;
200*7c478bd9Sstevel@tonic-gate opt.sopt_val = *addrs;
201*7c478bd9Sstevel@tonic-gate opt.sopt_len = bufsz;
202*7c478bd9Sstevel@tonic-gate if (ioctl(sock, SIOCSCTPGOPT, &opt) == -1) {
203*7c478bd9Sstevel@tonic-gate free(*addrs);
204*7c478bd9Sstevel@tonic-gate *addrs = NULL;
205*7c478bd9Sstevel@tonic-gate return (-1);
206*7c478bd9Sstevel@tonic-gate }
207*7c478bd9Sstevel@tonic-gate
208*7c478bd9Sstevel@tonic-gate /* Calculate the number of addresses returned. */
209*7c478bd9Sstevel@tonic-gate switch (((struct sockaddr *)*addrs)->sa_family) {
210*7c478bd9Sstevel@tonic-gate case AF_INET:
211*7c478bd9Sstevel@tonic-gate naddrs = opt.sopt_len / sizeof (struct sockaddr_in);
212*7c478bd9Sstevel@tonic-gate break;
213*7c478bd9Sstevel@tonic-gate case AF_INET6:
214*7c478bd9Sstevel@tonic-gate naddrs = opt.sopt_len / sizeof (struct sockaddr_in6);
215*7c478bd9Sstevel@tonic-gate break;
216*7c478bd9Sstevel@tonic-gate }
217*7c478bd9Sstevel@tonic-gate return (naddrs);
218*7c478bd9Sstevel@tonic-gate }
219*7c478bd9Sstevel@tonic-gate
220*7c478bd9Sstevel@tonic-gate void
sctp_freeladdrs(void * addrs)221*7c478bd9Sstevel@tonic-gate sctp_freeladdrs(void *addrs)
222*7c478bd9Sstevel@tonic-gate {
223*7c478bd9Sstevel@tonic-gate free(addrs);
224*7c478bd9Sstevel@tonic-gate }
225*7c478bd9Sstevel@tonic-gate
226*7c478bd9Sstevel@tonic-gate int
sctp_opt_info(int sock,sctp_assoc_t id,int opt,void * arg,socklen_t * len)227*7c478bd9Sstevel@tonic-gate sctp_opt_info(int sock, sctp_assoc_t id, int opt, void *arg, socklen_t *len)
228*7c478bd9Sstevel@tonic-gate {
229*7c478bd9Sstevel@tonic-gate struct sctpopt sopt;
230*7c478bd9Sstevel@tonic-gate
231*7c478bd9Sstevel@tonic-gate sopt.sopt_aid = id;
232*7c478bd9Sstevel@tonic-gate sopt.sopt_name = opt;
233*7c478bd9Sstevel@tonic-gate sopt.sopt_val = arg;
234*7c478bd9Sstevel@tonic-gate sopt.sopt_len = *len;
235*7c478bd9Sstevel@tonic-gate
236*7c478bd9Sstevel@tonic-gate if (ioctl(sock, SIOCSCTPGOPT, &sopt) == -1) {
237*7c478bd9Sstevel@tonic-gate return (-1);
238*7c478bd9Sstevel@tonic-gate }
239*7c478bd9Sstevel@tonic-gate *len = sopt.sopt_len;
240*7c478bd9Sstevel@tonic-gate return (0);
241*7c478bd9Sstevel@tonic-gate }
242*7c478bd9Sstevel@tonic-gate
243*7c478bd9Sstevel@tonic-gate /*
244*7c478bd9Sstevel@tonic-gate * Branch off an association to its own socket. ioctl() allocates and
245*7c478bd9Sstevel@tonic-gate * returns new fd.
246*7c478bd9Sstevel@tonic-gate */
247*7c478bd9Sstevel@tonic-gate int
sctp_peeloff(int sock,sctp_assoc_t id)248*7c478bd9Sstevel@tonic-gate sctp_peeloff(int sock, sctp_assoc_t id)
249*7c478bd9Sstevel@tonic-gate {
250*7c478bd9Sstevel@tonic-gate int fd;
251*7c478bd9Sstevel@tonic-gate
252*7c478bd9Sstevel@tonic-gate fd = id;
253*7c478bd9Sstevel@tonic-gate if (ioctl(sock, SIOCSCTPPEELOFF, &fd) == -1) {
254*7c478bd9Sstevel@tonic-gate return (-1);
255*7c478bd9Sstevel@tonic-gate }
256*7c478bd9Sstevel@tonic-gate return (fd);
257*7c478bd9Sstevel@tonic-gate }
258*7c478bd9Sstevel@tonic-gate
259*7c478bd9Sstevel@tonic-gate
260*7c478bd9Sstevel@tonic-gate ssize_t
sctp_recvmsg(int s,void * msg,size_t len,struct sockaddr * from,socklen_t * fromlen,struct sctp_sndrcvinfo * sinfo,int * msg_flags)261*7c478bd9Sstevel@tonic-gate sctp_recvmsg(int s, void *msg, size_t len, struct sockaddr *from,
262*7c478bd9Sstevel@tonic-gate socklen_t *fromlen, struct sctp_sndrcvinfo *sinfo, int *msg_flags)
263*7c478bd9Sstevel@tonic-gate {
264*7c478bd9Sstevel@tonic-gate struct msghdr hdr;
265*7c478bd9Sstevel@tonic-gate struct iovec iov;
266*7c478bd9Sstevel@tonic-gate struct cmsghdr *cmsg;
267*7c478bd9Sstevel@tonic-gate char cinmsg[sizeof (*sinfo) + sizeof (*cmsg) + _CMSG_HDR_ALIGNMENT];
268*7c478bd9Sstevel@tonic-gate int err;
269*7c478bd9Sstevel@tonic-gate
270*7c478bd9Sstevel@tonic-gate hdr.msg_name = from;
271*7c478bd9Sstevel@tonic-gate hdr.msg_namelen = (fromlen != NULL) ? *fromlen : 0;
272*7c478bd9Sstevel@tonic-gate hdr.msg_iov = &iov;
273*7c478bd9Sstevel@tonic-gate hdr.msg_iovlen = 1;
274*7c478bd9Sstevel@tonic-gate if (sinfo != NULL) {
275*7c478bd9Sstevel@tonic-gate hdr.msg_control = (void *)_CMSG_HDR_ALIGN(cinmsg);
276*7c478bd9Sstevel@tonic-gate hdr.msg_controllen = sizeof (cinmsg) -
277*7c478bd9Sstevel@tonic-gate (_CMSG_HDR_ALIGN(cinmsg) - (uintptr_t)cinmsg);
278*7c478bd9Sstevel@tonic-gate } else {
279*7c478bd9Sstevel@tonic-gate hdr.msg_control = NULL;
280*7c478bd9Sstevel@tonic-gate hdr.msg_controllen = 0;
281*7c478bd9Sstevel@tonic-gate }
282*7c478bd9Sstevel@tonic-gate
283*7c478bd9Sstevel@tonic-gate iov.iov_base = msg;
284*7c478bd9Sstevel@tonic-gate iov.iov_len = len;
285*7c478bd9Sstevel@tonic-gate err = recvmsg(s, &hdr, msg_flags == NULL ? 0 : *msg_flags);
286*7c478bd9Sstevel@tonic-gate if (err == -1) {
287*7c478bd9Sstevel@tonic-gate return (-1);
288*7c478bd9Sstevel@tonic-gate }
289*7c478bd9Sstevel@tonic-gate if (fromlen != NULL) {
290*7c478bd9Sstevel@tonic-gate *fromlen = hdr.msg_namelen;
291*7c478bd9Sstevel@tonic-gate }
292*7c478bd9Sstevel@tonic-gate if (msg_flags != NULL) {
293*7c478bd9Sstevel@tonic-gate *msg_flags = hdr.msg_flags;
294*7c478bd9Sstevel@tonic-gate }
295*7c478bd9Sstevel@tonic-gate if (sinfo != NULL) {
296*7c478bd9Sstevel@tonic-gate for (cmsg = CMSG_FIRSTHDR(&hdr); cmsg != NULL;
297*7c478bd9Sstevel@tonic-gate cmsg = CMSG_NXTHDR(&hdr, cmsg)) {
298*7c478bd9Sstevel@tonic-gate if (cmsg->cmsg_level == IPPROTO_SCTP &&
299*7c478bd9Sstevel@tonic-gate cmsg->cmsg_type == SCTP_SNDRCV) {
300*7c478bd9Sstevel@tonic-gate bcopy(CMSG_DATA(cmsg), sinfo, sizeof (*sinfo));
301*7c478bd9Sstevel@tonic-gate break;
302*7c478bd9Sstevel@tonic-gate }
303*7c478bd9Sstevel@tonic-gate }
304*7c478bd9Sstevel@tonic-gate }
305*7c478bd9Sstevel@tonic-gate return (err);
306*7c478bd9Sstevel@tonic-gate }
307*7c478bd9Sstevel@tonic-gate
308*7c478bd9Sstevel@tonic-gate static ssize_t
sctp_send_common(int s,const void * msg,size_t len,const struct sockaddr * to,socklen_t tolen,uint32_t ppid,uint32_t sinfo_flags,uint16_t stream_no,uint32_t timetolive,uint32_t context,sctp_assoc_t aid,int flags)309*7c478bd9Sstevel@tonic-gate sctp_send_common(int s, const void *msg, size_t len, const struct sockaddr *to,
310*7c478bd9Sstevel@tonic-gate socklen_t tolen, uint32_t ppid, uint32_t sinfo_flags, uint16_t stream_no,
311*7c478bd9Sstevel@tonic-gate uint32_t timetolive, uint32_t context, sctp_assoc_t aid, int flags)
312*7c478bd9Sstevel@tonic-gate {
313*7c478bd9Sstevel@tonic-gate struct msghdr hdr;
314*7c478bd9Sstevel@tonic-gate struct iovec iov;
315*7c478bd9Sstevel@tonic-gate struct sctp_sndrcvinfo *sinfo;
316*7c478bd9Sstevel@tonic-gate struct cmsghdr *cmsg;
317*7c478bd9Sstevel@tonic-gate char coutmsg[sizeof (*sinfo) + sizeof (*cmsg) + _CMSG_HDR_ALIGNMENT];
318*7c478bd9Sstevel@tonic-gate
319*7c478bd9Sstevel@tonic-gate hdr.msg_name = (caddr_t)to;
320*7c478bd9Sstevel@tonic-gate hdr.msg_namelen = tolen;
321*7c478bd9Sstevel@tonic-gate hdr.msg_iov = &iov;
322*7c478bd9Sstevel@tonic-gate hdr.msg_iovlen = 1;
323*7c478bd9Sstevel@tonic-gate hdr.msg_control = (void *)_CMSG_HDR_ALIGN(coutmsg);
324*7c478bd9Sstevel@tonic-gate hdr.msg_controllen = sizeof (*cmsg) + sizeof (*sinfo);
325*7c478bd9Sstevel@tonic-gate
326*7c478bd9Sstevel@tonic-gate iov.iov_len = len;
327*7c478bd9Sstevel@tonic-gate iov.iov_base = (caddr_t)msg;
328*7c478bd9Sstevel@tonic-gate
329*7c478bd9Sstevel@tonic-gate cmsg = CMSG_FIRSTHDR(&hdr);
330*7c478bd9Sstevel@tonic-gate cmsg->cmsg_level = IPPROTO_SCTP;
331*7c478bd9Sstevel@tonic-gate cmsg->cmsg_type = SCTP_SNDRCV;
332*7c478bd9Sstevel@tonic-gate cmsg->cmsg_len = sizeof (*cmsg) + sizeof (*sinfo);
333*7c478bd9Sstevel@tonic-gate
334*7c478bd9Sstevel@tonic-gate sinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg);
335*7c478bd9Sstevel@tonic-gate sinfo->sinfo_stream = stream_no;
336*7c478bd9Sstevel@tonic-gate sinfo->sinfo_ssn = 0;
337*7c478bd9Sstevel@tonic-gate sinfo->sinfo_flags = sinfo_flags;
338*7c478bd9Sstevel@tonic-gate sinfo->sinfo_ppid = ppid;
339*7c478bd9Sstevel@tonic-gate sinfo->sinfo_context = context;
340*7c478bd9Sstevel@tonic-gate sinfo->sinfo_timetolive = timetolive;
341*7c478bd9Sstevel@tonic-gate sinfo->sinfo_tsn = 0;
342*7c478bd9Sstevel@tonic-gate sinfo->sinfo_cumtsn = 0;
343*7c478bd9Sstevel@tonic-gate sinfo->sinfo_assoc_id = aid;
344*7c478bd9Sstevel@tonic-gate
345*7c478bd9Sstevel@tonic-gate return (sendmsg(s, &hdr, flags));
346*7c478bd9Sstevel@tonic-gate }
347*7c478bd9Sstevel@tonic-gate
348*7c478bd9Sstevel@tonic-gate ssize_t
sctp_send(int s,const void * msg,size_t len,const struct sctp_sndrcvinfo * sinfo,int flags)349*7c478bd9Sstevel@tonic-gate sctp_send(int s, const void *msg, size_t len,
350*7c478bd9Sstevel@tonic-gate const struct sctp_sndrcvinfo *sinfo, int flags)
351*7c478bd9Sstevel@tonic-gate {
352*7c478bd9Sstevel@tonic-gate /* Note that msg can be NULL for pure control message. */
353*7c478bd9Sstevel@tonic-gate if (sinfo == NULL) {
354*7c478bd9Sstevel@tonic-gate errno = EINVAL;
355*7c478bd9Sstevel@tonic-gate return (-1);
356*7c478bd9Sstevel@tonic-gate }
357*7c478bd9Sstevel@tonic-gate return (sctp_send_common(s, msg, len, NULL, 0, sinfo->sinfo_ppid,
358*7c478bd9Sstevel@tonic-gate sinfo->sinfo_flags, sinfo->sinfo_stream, sinfo->sinfo_timetolive,
359*7c478bd9Sstevel@tonic-gate sinfo->sinfo_context, sinfo->sinfo_assoc_id, flags));
360*7c478bd9Sstevel@tonic-gate }
361*7c478bd9Sstevel@tonic-gate
362*7c478bd9Sstevel@tonic-gate ssize_t
sctp_sendmsg(int s,const void * msg,size_t len,const struct sockaddr * to,socklen_t tolen,uint32_t ppid,uint32_t flags,uint16_t stream_no,uint32_t timetolive,uint32_t context)363*7c478bd9Sstevel@tonic-gate sctp_sendmsg(int s, const void *msg, size_t len, const struct sockaddr *to,
364*7c478bd9Sstevel@tonic-gate socklen_t tolen, uint32_t ppid, uint32_t flags, uint16_t stream_no,
365*7c478bd9Sstevel@tonic-gate uint32_t timetolive, uint32_t context)
366*7c478bd9Sstevel@tonic-gate {
367*7c478bd9Sstevel@tonic-gate return (sctp_send_common(s, msg, len, to, tolen, ppid, flags,
368*7c478bd9Sstevel@tonic-gate stream_no, timetolive, context, 0, 0));
369*7c478bd9Sstevel@tonic-gate }
370