1 /* SCTP kernel Implementation: User API extensions.
5 * Distributed under the terms of the LGPL v2.1 as described in
6 * http://www.gnu.org/copyleft/lesser.txt
8 * This file is part of the user library that offers support for the
9 * SCTP kernel Implementation. The main purpose of this
10 * code is to provide the SCTP Socket API mappings for user
11 * application to interface with the SCTP in kernel.
13 * This implementation is based on the Socket API Extensions for SCTP
14 * defined in <draft-ietf-tsvwg-sctpsocket-10.txt>
16 * Copyright (c) 2003 Intel Corp.
18 * Written or modified by:
19 * Ardelle Fan <ardelle.fan@intel.com>
23 #include <sys/socket.h> /* struct sockaddr_storage, setsockopt() */
24 #include <netinet/sctp.h>
26 /* This library function assists the user with the advanced features
27 * of SCTP. This is a new SCTP API described in the section 8.7 of the
28 * Sockets API Extensions for SCTP. This is implemented using the
29 * sendmsg() interface.
32 sctp_sendmsg(int s, const void *msg, size_t len, struct sockaddr *to,
33 socklen_t tolen, uint32_t ppid, uint32_t flags,
34 uint16_t stream_no, uint32_t timetolive, uint32_t context)
38 char outcmsg[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))];
40 struct sctp_sndrcvinfo *sinfo;
43 outmsg.msg_namelen = tolen;
44 outmsg.msg_iov = &iov;
45 iov.iov_base = (void *)msg;
47 outmsg.msg_iovlen = 1;
49 outmsg.msg_control = outcmsg;
50 outmsg.msg_controllen = sizeof(outcmsg);
53 cmsg = CMSG_FIRSTHDR(&outmsg);
54 cmsg->cmsg_level = IPPROTO_SCTP;
55 cmsg->cmsg_type = SCTP_SNDRCV;
56 cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
58 outmsg.msg_controllen = cmsg->cmsg_len;
59 sinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg);
60 memset(sinfo, 0, sizeof(struct sctp_sndrcvinfo));
61 sinfo->sinfo_ppid = ppid;
62 sinfo->sinfo_flags = flags;
63 sinfo->sinfo_stream = stream_no;
64 sinfo->sinfo_timetolive = timetolive;
65 sinfo->sinfo_context = context;
67 return sendmsg(s, &outmsg, 0);
70 /* This library function assist the user with sending a message without
71 * dealing directly with the CMSG header.
74 sctp_send(int s, const void *msg, size_t len,
75 const struct sctp_sndrcvinfo *sinfo, int flags)
80 outmsg.msg_name = NULL;
81 outmsg.msg_namelen = 0;
82 outmsg.msg_iov = &iov;
83 iov.iov_base = (void *)msg;
85 outmsg.msg_iovlen = 1;
86 outmsg.msg_controllen = 0;
89 char outcmsg[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))];
92 outmsg.msg_control = outcmsg;
93 outmsg.msg_controllen = sizeof(outcmsg);
96 cmsg = CMSG_FIRSTHDR(&outmsg);
97 cmsg->cmsg_level = IPPROTO_SCTP;
98 cmsg->cmsg_type = SCTP_SNDRCV;
99 cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
101 outmsg.msg_controllen = cmsg->cmsg_len;
102 memcpy(CMSG_DATA(cmsg), sinfo, sizeof(struct sctp_sndrcvinfo));
105 return sendmsg(s, &outmsg, flags);