blob: a4e1ed9b9bb97342acc9869f51710dd0baf11e1b [file] [log] [blame]
Austin Schuh8d0a2852019-12-28 22:54:28 -08001/* SCTP kernel Implementation: User API extensions.
2 *
3 * peeloff.c
4 *
5 * Distributed under the terms of the LGPL v2.1 as described in
6 * http://www.gnu.org/copyleft/lesser.txt
7 *
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.
12 *
13 * This implementation is based on the Socket API Extensions for SCTP
14 * defined in <draft-ietf-tsvwg-sctpsocket-10.txt.
15 *
16 * (C) Copyright IBM Corp. 2001, 2003
17 *
18 * Written or modified by:
19 * Sridhar Samudrala <sri@us.ibm.com>
20 */
21
22#include <sys/socket.h> /* struct sockaddr_storage, setsockopt() */
23#include <netinet/sctp.h> /* SCTP_SOCKOPT_BINDX_* */
24#include <errno.h>
25
26#ifdef HAVE_SCTP_PEELOFF_FLAGS
27int
28sctp_peeloff_flags(int fd, sctp_assoc_t associd, unsigned flags)
29{
30 socklen_t peeloff_size = sizeof(sctp_peeloff_flags_arg_t);
31 sctp_peeloff_flags_arg_t peeloff;
32 int err;
33
34 if (!flags)
35 return sctp_peeloff(fd, associd);
36
37 peeloff.p_arg.associd = associd;
38 peeloff.p_arg.sd = 0;
39 peeloff.flags = flags;
40
41 err = getsockopt(fd, SOL_SCTP, SCTP_SOCKOPT_PEELOFF_FLAGS, &peeloff,
42 &peeloff_size);
43
44 if (err < 0)
45 return err;
46
47 return peeloff.p_arg.sd;
48}
49#endif
50
51/* Branch off an association into a seperate socket. This is a new SCTP API
52 * described in the section 8.2 of the Sockets API Extensions for SCTP.
53 * This is implemented using the getsockopt() interface.
54 */
55int
56sctp_peeloff(int fd, sctp_assoc_t associd)
57{
58 socklen_t peeloff_size = sizeof(sctp_peeloff_arg_t);
59 sctp_peeloff_arg_t peeloff;
60 int err;
61
62 peeloff.associd = associd;
63 peeloff.sd = 0;
64
65 err = getsockopt(fd, SOL_SCTP, SCTP_SOCKOPT_PEELOFF, &peeloff,
66 &peeloff_size);
67
68 if (err < 0)
69 return err;
70
71 return peeloff.sd;
72}