1f08c3bdfSopenharmony_ci/* SCTP kernel Implementation: User API extensions. 2f08c3bdfSopenharmony_ci * 3f08c3bdfSopenharmony_ci * peeloff.c 4f08c3bdfSopenharmony_ci * 5f08c3bdfSopenharmony_ci * Distributed under the terms of the LGPL v2.1 as described in 6f08c3bdfSopenharmony_ci * http://www.gnu.org/copyleft/lesser.txt 7f08c3bdfSopenharmony_ci * 8f08c3bdfSopenharmony_ci * This file is part of the user library that offers support for the 9f08c3bdfSopenharmony_ci * SCTP kernel Implementation. The main purpose of this 10f08c3bdfSopenharmony_ci * code is to provide the SCTP Socket API mappings for user 11f08c3bdfSopenharmony_ci * application to interface with the SCTP in kernel. 12f08c3bdfSopenharmony_ci * 13f08c3bdfSopenharmony_ci * This implementation is based on the Socket API Extensions for SCTP 14f08c3bdfSopenharmony_ci * defined in <draft-ietf-tsvwg-sctpsocket-10.txt. 15f08c3bdfSopenharmony_ci * 16f08c3bdfSopenharmony_ci * (C) Copyright IBM Corp. 2001, 2003 17f08c3bdfSopenharmony_ci * 18f08c3bdfSopenharmony_ci * Written or modified by: 19f08c3bdfSopenharmony_ci * Sridhar Samudrala <sri@us.ibm.com> 20f08c3bdfSopenharmony_ci */ 21f08c3bdfSopenharmony_ci 22f08c3bdfSopenharmony_ci#include <sys/socket.h> /* struct sockaddr_storage, setsockopt() */ 23f08c3bdfSopenharmony_ci#include <netinet/sctp.h> /* SCTP_SOCKOPT_BINDX_* */ 24f08c3bdfSopenharmony_ci#include <errno.h> 25f08c3bdfSopenharmony_ci 26f08c3bdfSopenharmony_ci/* Branch off an association into a seperate socket. This is a new SCTP API 27f08c3bdfSopenharmony_ci * described in the section 8.2 of the Sockets API Extensions for SCTP. 28f08c3bdfSopenharmony_ci * This is implemented using the getsockopt() interface. 29f08c3bdfSopenharmony_ci */ 30f08c3bdfSopenharmony_ciint 31f08c3bdfSopenharmony_cisctp_peeloff(int fd, sctp_assoc_t associd) 32f08c3bdfSopenharmony_ci{ 33f08c3bdfSopenharmony_ci sctp_peeloff_arg_t peeloff; 34f08c3bdfSopenharmony_ci socklen_t peeloff_size = sizeof(peeloff); 35f08c3bdfSopenharmony_ci int err; 36f08c3bdfSopenharmony_ci 37f08c3bdfSopenharmony_ci peeloff.associd = associd; 38f08c3bdfSopenharmony_ci peeloff.sd = 0; 39f08c3bdfSopenharmony_ci err = getsockopt(fd, SOL_SCTP, SCTP_SOCKOPT_PEELOFF, &peeloff, 40f08c3bdfSopenharmony_ci &peeloff_size); 41f08c3bdfSopenharmony_ci if (err < 0) { 42f08c3bdfSopenharmony_ci return err; 43f08c3bdfSopenharmony_ci } 44f08c3bdfSopenharmony_ci 45f08c3bdfSopenharmony_ci return peeloff.sd; 46f08c3bdfSopenharmony_ci 47f08c3bdfSopenharmony_ci} /* sctp_peeloff() */ 48