1f08c3bdfSopenharmony_ci/* SCTP kernel Implementation: User API extensions. 2f08c3bdfSopenharmony_ci * 3f08c3bdfSopenharmony_ci * bindx.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 * Copyright (c) 2002 Intel Corporation. 18f08c3bdfSopenharmony_ci * 19f08c3bdfSopenharmony_ci * Written or modified by: 20f08c3bdfSopenharmony_ci * La Monte H.P. Yarroll <piggy@acm.org> 21f08c3bdfSopenharmony_ci * Daisy Chang <daisyc@us.ibm.com> 22f08c3bdfSopenharmony_ci * Inaky Perez-Gonzalez <inaky.gonzalez@intel.com> 23f08c3bdfSopenharmony_ci * Sridhar Samudrala <sri@us.ibm.com> 24f08c3bdfSopenharmony_ci */ 25f08c3bdfSopenharmony_ci 26f08c3bdfSopenharmony_ci#include <sys/socket.h> /* struct sockaddr_storage, setsockopt() */ 27f08c3bdfSopenharmony_ci#include <netinet/in.h> 28f08c3bdfSopenharmony_ci#include <netinet/sctp.h> /* SCTP_SOCKOPT_BINDX_* */ 29f08c3bdfSopenharmony_ci#include <errno.h> 30f08c3bdfSopenharmony_ci 31f08c3bdfSopenharmony_ci/* Support the sctp_bindx() interface. 32f08c3bdfSopenharmony_ci * 33f08c3bdfSopenharmony_ci * See Sockets API Extensions for SCTP. Section 8.1. 34f08c3bdfSopenharmony_ci * 35f08c3bdfSopenharmony_ci * Instead of implementing through a socket call in sys_socketcall(), 36f08c3bdfSopenharmony_ci * tunnel the request through setsockopt(). 37f08c3bdfSopenharmony_ci */ 38f08c3bdfSopenharmony_ciint 39f08c3bdfSopenharmony_cisctp_bindx(int fd, struct sockaddr *addrs, int addrcnt, int flags) 40f08c3bdfSopenharmony_ci{ 41f08c3bdfSopenharmony_ci int setsock_option = 0; 42f08c3bdfSopenharmony_ci void *addrbuf; 43f08c3bdfSopenharmony_ci struct sockaddr *sa_addr; 44f08c3bdfSopenharmony_ci socklen_t addrs_size = 0; 45f08c3bdfSopenharmony_ci int i; 46f08c3bdfSopenharmony_ci 47f08c3bdfSopenharmony_ci switch (flags) { 48f08c3bdfSopenharmony_ci case SCTP_BINDX_ADD_ADDR: 49f08c3bdfSopenharmony_ci setsock_option = SCTP_SOCKOPT_BINDX_ADD; 50f08c3bdfSopenharmony_ci break; 51f08c3bdfSopenharmony_ci case SCTP_BINDX_REM_ADDR: 52f08c3bdfSopenharmony_ci setsock_option = SCTP_SOCKOPT_BINDX_REM; 53f08c3bdfSopenharmony_ci break; 54f08c3bdfSopenharmony_ci default: 55f08c3bdfSopenharmony_ci errno = EINVAL; 56f08c3bdfSopenharmony_ci return -1; 57f08c3bdfSopenharmony_ci } 58f08c3bdfSopenharmony_ci 59f08c3bdfSopenharmony_ci addrbuf = addrs; 60f08c3bdfSopenharmony_ci for (i = 0; i < addrcnt; i++) { 61f08c3bdfSopenharmony_ci sa_addr = (struct sockaddr *)addrbuf; 62f08c3bdfSopenharmony_ci switch (sa_addr->sa_family) { 63f08c3bdfSopenharmony_ci case AF_INET: 64f08c3bdfSopenharmony_ci addrs_size += sizeof(struct sockaddr_in); 65f08c3bdfSopenharmony_ci addrbuf += sizeof(struct sockaddr_in); 66f08c3bdfSopenharmony_ci break; 67f08c3bdfSopenharmony_ci case AF_INET6: 68f08c3bdfSopenharmony_ci addrs_size += sizeof(struct sockaddr_in6); 69f08c3bdfSopenharmony_ci addrbuf += sizeof(struct sockaddr_in6); 70f08c3bdfSopenharmony_ci break; 71f08c3bdfSopenharmony_ci default: 72f08c3bdfSopenharmony_ci errno = EINVAL; 73f08c3bdfSopenharmony_ci return -1; 74f08c3bdfSopenharmony_ci } 75f08c3bdfSopenharmony_ci } 76f08c3bdfSopenharmony_ci 77f08c3bdfSopenharmony_ci return setsockopt(fd, SOL_SCTP, setsock_option, addrs, addrs_size); 78f08c3bdfSopenharmony_ci} 79