99 строки
3.1 KiB
C
99 строки
3.1 KiB
C
/*
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
* University Research and Technology
|
|
* Corporation. All rights reserved.
|
|
* Copyright (c) 2004-2006 The University of Tennessee and The University
|
|
* of Tennessee Research Foundation. All rights
|
|
* reserved.
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
* University of Stuttgart. All rights reserved.
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
* All rights reserved.
|
|
* $COPYRIGHT$
|
|
*
|
|
* Additional copyrights may follow
|
|
*
|
|
* $HEADER$
|
|
*/
|
|
|
|
/* SCTP kernel reference Implementation: User API extensions.
|
|
*
|
|
* sendmsg.c
|
|
*
|
|
* Distributed under the terms of the LGPL v2.1 as described in
|
|
* http://www.gnu.org/copyleft/lesser.txt
|
|
*
|
|
* This file is part of the user library that offers support for the
|
|
* SCTP kernel reference Implementation. The main purpose of this
|
|
* code is to provide the SCTP Socket API mappings for user
|
|
* application to interface with the SCTP in kernel.
|
|
*
|
|
* This implementation is based on the Socket API Extensions for SCTP
|
|
* defined in <draft-ietf-tsvwg-sctpsocket-10.txt>
|
|
*
|
|
* Copyright (c) 2003 Intel Corp.
|
|
*
|
|
* Written or modified by:
|
|
* Ardelle Fan <ardelle.fan@intel.com>
|
|
*/
|
|
|
|
|
|
/* Small modifications made by Karol Mroz (kmroz). */
|
|
|
|
/* #include <string.h>
|
|
* #include <sys/socket.h>
|
|
* #include <netinet/sctp.h>
|
|
*/
|
|
#include "sctp_writev.h"
|
|
|
|
/* This library function assists the user with the advanced features
|
|
* of SCTP. This is a new SCTP API described in the section 8.7 of the
|
|
* Sockets API Extensions for SCTP. This is implemented using the
|
|
* sendmsg() interface.
|
|
*
|
|
* kmroz: Modification to this was trivial. const char* was replaced with const
|
|
* struct iovec* and the sendmsg call was replaced with a call to writev that
|
|
* takes *vector as a parameter.
|
|
*/
|
|
|
|
int
|
|
sctp_writev(int s, /* const */ struct iovec *vector, size_t len, struct sockaddr *to,
|
|
socklen_t tolen, uint32_t ppid, uint32_t flags,
|
|
uint16_t stream_no, uint32_t timetolive, uint32_t context)
|
|
{
|
|
struct msghdr outmsg;
|
|
struct iovec iov;
|
|
char outcmsg[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))];
|
|
struct cmsghdr *cmsg;
|
|
struct sctp_sndrcvinfo *sinfo;
|
|
|
|
outmsg.msg_name = to;
|
|
outmsg.msg_namelen = tolen;
|
|
/* outmsg.msg_iov = &iov; */
|
|
outmsg.msg_iov = vector;
|
|
iov.iov_base = vector->iov_base;
|
|
iov.iov_len = vector->iov_len;
|
|
outmsg.msg_iovlen = 1;
|
|
|
|
outmsg.msg_control = outcmsg;
|
|
outmsg.msg_controllen = sizeof(outcmsg);
|
|
outmsg.msg_flags = 0;
|
|
|
|
cmsg = CMSG_FIRSTHDR(&outmsg);
|
|
cmsg->cmsg_level = IPPROTO_SCTP;
|
|
cmsg->cmsg_type = SCTP_SNDRCV;
|
|
cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
|
|
|
|
outmsg.msg_controllen = cmsg->cmsg_len;
|
|
sinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg);
|
|
memset(sinfo, 0, sizeof(struct sctp_sndrcvinfo));
|
|
sinfo->sinfo_ppid = ppid;
|
|
sinfo->sinfo_flags = flags;
|
|
sinfo->sinfo_stream = stream_no;
|
|
sinfo->sinfo_timetolive = timetolive;
|
|
sinfo->sinfo_context = context;
|
|
|
|
return sendmsg(s, &outmsg, 0);
|
|
/* return writev(s, vector, len); */
|
|
}
|