diff -r 1543042d70c5 lib/libsctp/Makefile
--- a/lib/libsctp/Makefile	Wed Jul 05 21:54:25 2006 +0200
+++ b/lib/libsctp/Makefile	Sat Jul 08 22:37:32 2006 +0200
@@ -3,4 +3,6 @@ LIB=	sctp
 LIB=	sctp
 SRCS=	sctp_sys_calls.c
 
+MAN=	sctp_recvmsg.3 sctp_send.3 sctp_sendmsg.3
+
 .include <bsd.lib.mk>
diff -r 1543042d70c5 lib/libsctp/sctp_recvmsg.3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libsctp/sctp_recvmsg.3	Sat Jul 08 22:37:32 2006 +0200
@@ -0,0 +1,291 @@
+.\" Copyright (c) 1983, 1991, 1993
+.\"	The Regents of the University of California.  All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\"    must display the following acknowledgement:
+.\"	This product includes software developed by the University of
+.\"	California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\"    may be used to endorse or promote products derived from this software
+.\"    without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\"     From: @(#)send.2	8.2 (Berkeley) 2/21/94
+.\" $FreeBSD: src/lib/libc/sys/send.2,v 1.32 2005/06/15 19:04:04 ru Exp $
+.\" $DragonFly$
+.\"
+.Dd July 8, 2006
+.Dt SCTP_RECVMSG 2
+.Os
+.Sh NAME
+.Nm sctp_recvmsg
+.Nd send a message from an SCTP socket
+.Sh LIBRARY
+.Lb libsctp
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/socket.h
+.In sys/sctp.h
+.Ft ssize_t
+.Fo sctp_recvmsg
+.Fa "int s"
+.Fa "const void *msg"
+.Fa "size_t len"
+.Fa "const struct sockaddr *from"
+.Fa "socklen_t fromlen"
+.Fa "struct sctp_sndrcvinfo *sinfo"
+.Fa "int *flags"
+.Fc
+.Sh DESCRIPTION
+The
+.Nm
+system call is used to receive a message from another SCTP endpoint.
+It is called by one-to-one
+.Pf ( Dv SOCK_STREAM )
+type sockets after a sucessful
+.Fn connect 2
+call or after the application has performed a
+.Fn listen
+followed by a sucessful
+.Fn accept 2 .
+For a one-to-many
+.Pf ( Dv SOCK_SEQPACKET )
+type socket, an endpoint may call
+.Nm
+after having implicitly started an association via one
+of the send calls including
+.Fn sctp_sendmsg 2
+.Fn sendto 2
+and
+.Fn sendmsg 2
+Or, an application may also receive a message after having
+called
+.Fn listen 2
+with a postive backlog to enable the reception of new associations.
+.Pp
+The address of the sender is held in the
+.Fa from
+argument with
+.Fa fromlen
+specifying its size.
+At the completion of a sucessful
+.Nm
+call
+.Fa from
+will hold the address of the peer and
+.Fa fromlen
+will hold the length of that address.
+Note that
+the address is bounded by the inital value of
+.Fa fromlen
+which is used as an in/out variable.
+.Pp
+The length of the message
+.Fa msg
+to be received is bounded by
+.Fa len .
+If the message is too long to fit in the users'
+receive buffer, then the
+.Fa flags
+argument will NOT have the
+.Dv MSG_EOF
+flag applied.
+If the message is a complete message then the
+.Fa flags
+argument will have
+.Dv MSG_EOF
+set.
+Locally detected errors are indicated by a return value of -1 with
+.Va errno
+set accordingly.
+The
+.Fa flags
+argument may also hold the value
+.Dv MSG_NOTIFICATION .
+When this occurs this indicates that the message received is NOT from
+the peer endpoint, but instead is a notification from the
+SCTP stack (see
+.Xr sctp 4
+for more details).
+Note that no notifications are ever given unless the user subscribes to
+such notifications using the
+.Dv SCTP_EVENTS
+socket option.
+.Pp
+If no message is available at the socket then
+.Nm
+normally blocks on the reception of a message or NOTIFICATION, unless
+the socket has been placed in non-blocking I/O mode.
+The
+.Xr select 2
+system call may be used to determine when it is possible to
+receive a message.
+.Pp
+The
+.Fa sinfo
+argument is defined as follows.
+.Bd -literal
+struct sctp_sndrcvinfo {
+	u_int16_t sinfo_stream;  /* Stream arriving on */
+	u_int16_t sinfo_ssn;     /* Stream Sequence Number */
+	u_int16_t sinfo_flags;   /* Flags on the incoming message */
+	u_int32_t sinfo_ppid;    /* The ppid field */
+	u_int32_t sinfo_context; /* context field */
+	u_int32_t sinfo_timetolive; /* not used by sctp_recvmsg */
+	u_int32_t sinfo_tsn;        /* The transport sequence number */
+	u_int32_t sinfo_cumtsn;     /* The cumulative acknowledgment point  */
+	sctp_assoc_t sinfo_assoc_id; /* The association id of the peer */
+};
+.Ed
+The
+.Fa sinfo->sinfo_ppid
+is an opaque 32 bit value that is passed transparently
+through the stack from the peer endpoint.
+Note that the stack passes this value without regard to byte
+order.
+.Pp
+The
+.Fa sinfo->sinfo_flags
+field may include the following:
+.Bd -literal
+#define SCTP_UNORDERED 	  0x0400	/* Message is un-ordered */
+.Ed
+.Pp
+The
+.Dv SCTP_UNORDERED
+flag is used to specify that the message arrived with no
+specific order and was delivered to the peer application
+as soon as possible.
+When this flag is absent the message was delivered in
+order within the stream it was received.
+.Pp
+.Fa sinfo->sinfo_stream
+is the SCTP stream that the message was received on.
+Streams in SCTP are reliable (or partially reliable) flows of ordered
+messages.
+.Pp
+The
+.Fa sinfo->sinfo_context
+field is used only if the local application set an association level
+context with the
+.Dv SCTP_CONTEXT
+socket option.
+Optionally, a user process can use this value to index some application
+specific data structure for all data coming from a specific association.
+.Pp
+The
+.Fa sinfo->sinfo_ssn
+will hold the stream sequence number assigned
+by the peer endpoint if the message is NOT unordered.
+For unordered messages this field holds an undefined value.
+.Pp
+The
+.Fa sinfo->sinfo_tsn
+holds a transport sequence number (TSN) that was assigned
+to this message by the peer endpoint.
+For messages that fit in or less than the path MTU this
+will be the only TSN assigned.
+Note that for messages that span multiple TSNs this
+value will be one of the TSNs that were used on the
+message.
+.Pp
+The
+.Fa sinfo->sinfo_cumtsn
+holds the current cumulative acknowledgment point of
+the transport association.
+Note that this may be larger or smaller than the TSN
+assigned to the message itself.
+.Pp
+The
+sinfo->sinfo_assoc_id
+is the unique association identification that was assigned
+to the association.
+For one-to-many
+.Pf ( Dv SOCK_SEQPACKET )
+type sockets this value
+can be used to send data to the peer without the use of
+an address field.
+It is also quite useful in setting various socket options
+on the specific association (see
+.Xr sctp 4 ) .
+.Pp
+The
+sinfo->info_timetolive
+field is not used by
+.Nm .
+.Sh RETURN VALUES
+.Rv -std sctp_recvmsg
+.Sh ERRORS
+The
+.Nm
+system call will fail if:
+.Bl -tag -width ".Er EHOSTUNREACH"
+.It Bq Er EBADF
+An invalid descriptor was specified.
+.It Bq Er ENOTSOCK
+The argument
+.Fa s
+is not a socket.
+.It Bq Er EFAULT
+An invalid user space address was specified for an argument.
+.It Bq Er EMSGSIZE
+The socket requires that a message is to be sent atomically,
+and the size of the message to be sent made this impossible.
+.It Bq Er EAGAIN
+The socket is marked non-blocking and the requested operation
+would block.
+.It Bq Er ENOBUFS
+The system was unable to allocate an internal buffer.
+The operation may succeed when buffers become available.
+.It Bq Er ENOBUFS
+The output queue for a network interface was full.
+This generally indicates that the interface has stopped sending,
+but may be caused by transient congestion.
+.It Bq Er EHOSTUNREACH
+The remote host was unreachable.
+.It Bq Er ENOTCON
+On a one to one style socket no association exists.
+.It Bq Er ECONNRESET
+An abort was received by the stack while the user was
+attempting to send data to the peer.
+.It Bq Er ENOENT
+On a one to many style socket no address is specified
+so that the association cannot be located or the
+.Dv SCTP_ABORT
+flag was specified on a non-existing association.
+.It Bq Er EPIPE
+The socket is unable to send anymore data
+.Pf ( Dv SBS_CANTSENDMORE
+has been set on the socket).
+This typically means that the socket
+is not connected and is a one-to-one style socket.
+.El
+.Sh SEE ALSO
+.Xr getsockopt 2 ,
+.Xr recv 2 ,
+.Xr sctp_send 2 ,
+.Xr sctp_sendmsg 2 ,
+.Xr select 2 ,
+.Xr sendmsg 2 ,
+.Xr setsockopt 2 ,
+.Xr socket 2 ,
+.Xr write 2
diff -r 1543042d70c5 lib/libsctp/sctp_send.3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libsctp/sctp_send.3	Sat Jul 08 22:37:32 2006 +0200
@@ -0,0 +1,320 @@
+.\" Copyright (c) 1983, 1991, 1993
+.\"	The Regents of the University of California.  All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\"    must display the following acknowledgement:
+.\"	This product includes software developed by the University of
+.\"	California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\"    may be used to endorse or promote products derived from this software
+.\"    without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\"     From: @(#)send.2	8.2 (Berkeley) 2/21/94
+.\" $FreeBSD: src/lib/libsctp/sys/send.2,v 1.32 2005/06/15 19:04:04 ru Exp $
+.\" $DragonFly$
+.\"
+.Dd July 8, 2006
+.Dt SCTP_SEND 2
+.Os
+.Sh NAME
+.Nm sctp_send
+.Nd send a message from an SCTP socket
+.Sh LIBRARY
+.Lb libsctp
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/socket.h
+.In sys/sctp.h
+.Ft ssize_t
+.Fo sctp_send
+.Fa "int sd"
+.Fa "const void *msg"
+.Fa "size_t len"
+.Fa "const struct sctp_sndrcvinfo *sinfo"
+.Fa "int flags"
+.Fc
+.Sh DESCRIPTION
+The
+.Nm
+system call is used to transmit a message to another SCTP endpoint and
+may be called to send data to an existing association for both one-to-many
+.Pf ( Dv SOCK_SEQPACKET )
+and one-to-one
+.Pf ( Dv SOCK_STREAM )
+socket types.
+The length of the message
+.Fa msg
+is given by
+.Fa len .
+If the message is too long to pass atomically through the
+underlying protocol, the
+.Va errno
+is set to
+.Er EMSGSIZE ,
+a -1 is returned, and the message is not transmitted.
+.Pp
+No indication of failure to deliver is implicit in a
+.Nm .
+Locally detected errors are indicated by a return value of -1.
+.Pp
+If no message space is available at the socket to hold
+the message to be transmitted, then
+.Nm
+will block, unless the socket has been placed in
+non-blocking I/O mode.
+The
+.Fn select 2
+system call may be used to determine when it is possible to
+send more data on one-to-one type
+.Pf ( Dv SOCK_STREAM )
+sockets.
+.Pp
+The
+.Fa sinfo
+structure is used to control various SCTP features
+and has the following format:
+.Bd -literal
+struct sctp_sndrcvinfo {
+	u_int16_t sinfo_stream;  /* Stream sending to */
+	u_int16_t sinfo_ssn;     /* valid for recv only */
+	u_int16_t sinfo_flags;   /* flags to control sending */
+	u_int32_t sinfo_ppid;    /* ppid field */
+	u_int32_t sinfo_context; /* context field */
+	u_int32_t sinfo_timetolive; /* timetolive for PR-SCTP */
+	u_int32_t sinfo_tsn;        /* valid for recv only */
+	u_int32_t sinfo_cumtsn;     /* valid for recv only */
+	sctp_assoc_t sinfo_assoc_id; /* The association id */
+};
+.Ed
+The
+.Fa sinfo->sinfo_ppid
+argument is an opaque 32 bit value that is passed transparently
+through the stack to the peer endpoint.
+It will be available on reception of a message (see
+.Xr sctp_recvmsg 2 ) .
+Note that the stack passes this value without regard to byte
+order.
+.Pp
+The
+.Fa sinfo->sinfo_flags
+argument may include one or more of the following:
+.Bd -literal
+#define SCTP_EOF 	  0x0100	/* Start a shutdown procedures */
+#define SCTP_ABORT	  0x0200	/* Send an ABORT to peer */
+#define SCTP_UNORDERED 	  0x0400	/* Message is un-ordered */
+#define SCTP_ADDR_OVER	  0x0800	/* Override the primary-address */
+#define SCTP_SENDALL      0x1000	/* Send this on all associations */
+					/* for the endpoint */
+/* The lower byte is an enumeration of PR-SCTP policies */
+#define SCTP_PR_SCTP_TTL  0x0001	/* Time based PR-SCTP */
+#define SCTP_PR_SCTP_BUF  0x0002	/* Buffer based PR-SCTP */
+#define SCTP_PR_SCTP_RTX  0x0003	/* Number of retransmissions based PR-SCTP */
+.Ed
+.Pp
+The flag
+.Dv SCTP_EOF
+is used to instruct the SCTP stack to queue this message
+and then start a graceful shutdown of the association.
+All remaining data in queue will be sent after which the association
+will be shutdown.
+.Pp
+.Dv SCTP_ABORT
+is used to immediately terminate an association.
+An abort is sent to the peer and the local TCB is destroyed.
+.Pp
+.Dv SCTP_UNORDERED
+is used to specify that the message being sent has no
+specific order and should be delivered to the peer application
+as soon as possible.
+When this flag is absent messages
+are delivered in order within the stream they are sent, but without
+respect to order to peer streams.
+.Pp
+The flag
+.Dv SCTP_ADDR_OVER
+is used to specify that a specific address should be used.
+Normally,
+SCTP will use only one of a multi-homed peers address as the primary
+address to send to.
+By default, no matter what the
+.Fa to
+argument is, this primary address is used to send data.
+By specifying
+this flag, the user is asking the stack to ignore the primary address
+and instead use the specified address not only has a lookup mechanism
+to find the association but also has the actual address to send to.
+.Pp
+For a one-to-many type
+.Pf ( Dv SOCK_SEQPACKET )
+socket the flag
+.Dv SCTP_SENDALL
+can be used as a convient way to make one send call and have
+all associations that are under the socket get a copy of the message.
+Note that this mechanism is quite efficent and makes only one actual
+copy of the data which is shared by all the associations for sending.
+.Pp
+The remaining flags are used for the partial reliability extension (RFC3758)
+and will only be effective if the peer endpoint supports this extension.
+This option specifies what local policy the local endpoint should use
+in skipping data.
+If none of these options are set, then data is never skipped over.
+.Pp
+.Dv SCTP_PR_SCTP_TTL
+Is used to indicate that a time based lifetime is being applied
+to the data.
+The
+.Fa sinfo->sinfo_timetolive
+argument is then a number of milliseconds for which the data is
+attempted to be transmitted.
+If that many milliseconds elapses
+and the peer has not acknowledged the data, the data will be
+skipped and no longer be transmitted.
+Note that this policy does
+not even assure that the data will ever be sent.
+In times of a congestion with large amounts of data being queued, the
+.Fa sinfo->sinfo_timetolive
+may expire before the first transmission is ever made.
+.Pp
+The
+.Dv SCTP_PR_SCTP_BUF
+based policy transforms the
+.Fa sinfo->sinfo_timetolive
+field into a total number of bytes allowed on the outbound
+send queue.
+If that number or more bytes are in queue, then
+other buffer based sends are looked to be removed and
+skipped.
+Note that this policy may also result in the data
+never being sent if no buffer based sends are in queue and
+the maximum specified by
+.Fa timetolive
+bytes is in queue.
+.Pp
+The
+.Dv SCTP_PR_SCTP_RTX
+policy transforms the
+.Fa sinfo->sinfo_timetolive
+into a number of retransmissions to allow.
+This policy
+always assures that at a minimum one send attempt is
+made of the data.
+After which no more than
+.Fa sinfo->sinfo_timetolive
+retransmissions will be made before the data is skipped.
+.Pp
+.Fa sinfo->sinfo_stream
+is the SCTP stream that you wish to send the
+message on.
+Streams in SCTP are reliable (or partially reliable) flows of ordered
+messages.
+.Pp
+The
+.Fa sinfo->sinfo_assoc_id
+field is used to
+select the association to send to on an one-to-many socket.
+For a one-to-one socket, this field is ignored.
+.Pp
+.Fa sinfo->sinfo_context
+field is used only in the event the message cannot be sent.
+This is an opaque
+value that the stack retains and will give to the user when a failed send
+is given if that notification is enabled (see
+.Xr sctp 4 ) .
+Normally a user process can use this value to index some application
+specific data structure when a send cannot be fulfilled.
+.Pp
+The
+.Fa flags
+argument holds the same meaning and values has those found in
+.Fn sendmsg 2
+but is generally ignored by SCTP.
+.Pp
+The
+.Fa sinfo->sinfo_ssn ,
+.Fa sinfo->sinfo_tsn ,
+and
+.Fa sinfo->sinfo_cumtsn
+fields are used only when receiving messages and are thus ignored by
+.Nm .
+.Sh RETURN VALUES
+.Rv -std sctp_send
+.Sh ERRORS
+The
+.Nm
+system call will fail if:
+.Bl -tag -width ".Er EHOSTUNREACH"
+.It Bq Er EBADF
+An invalid descriptor was specified.
+.It Bq Er ENOTSOCK
+The argument
+.Fa s
+is not a socket.
+.It Bq Er EFAULT
+An invalid user space address was specified for an argument.
+.It Bq Er EMSGSIZE
+The socket requires that a message is to be sent atomically,
+and the size of the message to be sent made this impossible.
+.It Bq Er EAGAIN
+The socket is marked non-blocking and the requested operation
+would block.
+.It Bq Er ENOBUFS
+The system was unable to allocate an internal buffer.
+The operation may succeed when buffers become available.
+.It Bq Er ENOBUFS
+The output queue for a network interface was full.
+This generally indicates that the interface has stopped sending,
+but may be caused by transient congestion.
+.It Bq Er EHOSTUNREACH
+The remote host was unreachable.
+.It Bq Er ENOTCON
+On a one to one style socket no association exists.
+.It Bq Er ECONNRESET
+An abort was received by the stack while the user was
+attempting to send data to the peer.
+.It Bq Er ENOENT
+On a one to many style socket no address is specified
+so that the association cannot be located or the
+.Dv SCTP_ABORT
+flag was specified on a non-existing association.
+.It Bq Er EPIPE
+The socket is unable to send anymore data
+.Pf ( Dv SBS_CANTSENDMORE
+has been set on the socket).
+This typically means that the socket
+is not connected and is a one-to-one style socket.
+.El
+.Sh SEE ALSO
+.Xr getsockopt 2 ,
+.Xr recv 2 ,
+.Xr sctp_recvmsg 2 ,
+.Xr sctp_sendmsg 2 ,
+.Xr select 2 ,
+.Xr sendmsg 2 ,
+.Xr socket 2 ,
+.Xr write 2
+.Sh BUGS
+Because
+.Nm
+may have multiple associations under one endpoint, a
+select on write will only work for a one-to-one style
+socket.
diff -r 1543042d70c5 lib/libsctp/sctp_sendmsg.3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libsctp/sctp_sendmsg.3	Sat Jul 08 22:37:32 2006 +0200
@@ -0,0 +1,313 @@
+.\" Copyright (c) 1983, 1991, 1993
+.\"	The Regents of the University of California.  All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\"    must display the following acknowledgement:
+.\"	This product includes software developed by the University of
+.\"	California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\"    may be used to endorse or promote products derived from this software
+.\"    without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\"     From: @(#)send.2	8.2 (Berkeley) 2/21/94
+.\" $FreeBSD: src/lib/libsctp/sys/send.2,v 1.32 2005/06/15 19:04:04 ru Exp $
+.\" $DragonFly$
+.\"
+.Dd July 8, 2006
+.Dt SCTP_SENDMSG 2
+.Os
+.Sh NAME
+.Nm sctp_sendmsg
+.Nd send a message from an SCTP socket
+.Sh LIBRARY
+.Lb libsctp
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/socket.h
+.In sys/sctp.h
+.Ft ssize_t
+.Fo sctp_sendmsg
+.Fa "int s"
+.Fa "const void *msg"
+.Fa "size_t len"
+.Fa "const struct sockaddr *to"
+.Fa "socklen_t tolen"
+.Fa "uint32_t ppid"
+.Fa "uint32_t flags"
+.Fa "uint16_t stream_no"
+.Fa "uint32_t timetolive"
+.Fa "uint32_t context"
+.Fc
+.Sh DESCRIPTION
+The
+.Nm
+system call is used to transmit a message to another SCTP endpoint and
+may be called at any time.
+If the socket is a one-to-many type
+.Pf ( Dv SOCK_SEQPACKET )
+socket then an attempt to send to an address that no association exists to will
+implicitly create a new association.
+Data sent in such an instance will result in
+the data being sent on the third leg of the SCTP four-way handshake.
+Note that if
+the socket is a one-to-one type
+.Pf ( Dv SOCK_STREAM )
+socket then an association must
+be in existence (by use of the 
+.Xr connect 2
+system call).
+Calling 
+.Nm
+on a non-connected one-to-one socket will result in the
+.Va errno
+being set to
+.Er ENOTCONN ,
+a -1 being returned, and the message is not transmitted.
+.Pp
+The address of the target is given by
+.Fa to
+with
+.Fa tolen
+specifying its size.
+The length of the message 
+.Fa msg
+is given by
+.Fa len .
+If the message is too long to pass atomically through the
+underlying protocol, the
+.Va errno
+is set to 
+.Er EMSGSIZE ,
+a -1 is returned, and
+the message is not transmitted.
+.Pp
+No indication of failure to deliver is implicit in a
+.Nm .
+Locally detected errors are indicated by a return value of -1.
+.Pp
+If no message space is available at the socket to hold
+the message to be transmitted, then
+.Nm
+blocks, unless the socket has been placed in
+non-blocking I/O mode.
+The
+.Fn select 2
+system call may be used to determine when it is possible to
+send more data on one-to-one type
+.Pf ( Dv SOCK_STREAM )
+sockets.
+.Pp
+The 
+.Fa ppid
+argument is an opaque 32 bit value that is passed transparently
+through the stack to the peer endpoint.
+It will be available on
+reception of a message (see
+.Xr sctp_recvmsg 2 ) .
+Note that the stack passes this value without regard to byte
+order.
+.Pp
+The
+.Fa flags
+argument may include one or more of the following:
+.Bd -literal
+#define SCTP_EOF 	  0x0100	/* Start a shutdown procedures */
+#define SCTP_ABORT	  0x0200	/* Send an ABORT to peer */
+#define SCTP_UNORDERED 	  0x0400	/* Message is un-ordered */
+#define SCTP_ADDR_OVER	  0x0800	/* Override the primary-address */
+#define SCTP_SENDALL      0x1000	/* Send this on all associations */
+					/* for the endpoint */
+/* The lower byte is an enumeration of PR-SCTP policies */
+#define SCTP_PR_SCTP_TTL  0x0001	/* Time based PR-SCTP */
+#define SCTP_PR_SCTP_BUF  0x0002	/* Buffer based PR-SCTP */
+#define SCTP_PR_SCTP_RTX  0x0003	/* Number of retransmissions based PR-SCTP */
+.Ed
+.Pp
+The flag 
+.Dv SCTP_EOF
+is used to instruct the SCTP stack to queue this message
+and then start a graceful shutdown of the association.
+All
+remaining data in queue will be sent after which the association
+will be shutdown.
+.Pp
+.Dv SCTP_ABORT
+is used to immediately terminate an association.
+An abort is sent to the peer and the local TCB is destroyed.
+.Pp
+.Dv SCTP_UNORDERED
+is used to specify that the message being sent has no
+specific order and should be delivered to the peer application
+as soon as possible.
+When this flag is absent messages
+are delivered in order within the stream they are sent, but without
+respect to order to peer streams.
+.Pp
+The flag
+.Dv SCTP_ADDR_OVER
+is used to specify that a specific address should be used.
+Normally,
+SCTP will use only one of a multi-homed peers address as the primary
+address to send to.
+By default, no matter what the 
+.Fa to
+argument is, this primary address is used to send data.
+By specifying
+this flag, the user is asking the stack to ignore the primary address
+and instead use the specified address not only has a lookup mechanism
+to find the association but also has the actual address to send to.
+.Pp
+For a one-to-many type
+.Pf ( Dv SOCK_SEQPACKET )
+socket the flag
+.Dv SCTP_SENDALL
+can be used as a convient way to make one send call and have
+all associations that are under the socket get a copy of the message.
+Note that this mechanism is quite efficent and makes only one actual
+copy of the data which is shared by all the associations for sending.
+.Pp
+The remaining flags are used for the partial reliabilty extension (RFC3758)
+and will only be effective if the peer endpoint supports this extension.
+This option specifies what local policy the local endpoint should use
+in skipping data.
+If none of these options are set, then data is never skipped over.
+.Pp
+.Dv SCTP_PR_SCTP_TTL
+Is used to indicate that a time based lifetime is being applied
+to the data.
+The
+.Fa timetolive
+argument is then a number of milliseconds for which the data is
+attempted to be transmitted.
+If that many milliseconds ellapses
+and the peer has not acknowledged the data, the data will be
+skipped and no longer be transmitted.
+Note that this policy does
+not even assure that the data will ever be sent.
+In times of a congestion
+with large amounts of data being queued, the 
+.Fa timetolive
+may expire before the first transmission is ever made.
+.Pp
+The
+.Dv SCTP_PR_SCTP_BUF
+based policy transforms the
+.Fa timetolive 
+field into a total number of bytes allowed on the outbound
+send queue.
+If that number or more bytes are in queue, then
+other buffer based sends are looked to be removed and
+skipped.
+Note that this policy may also result in the data
+never being sent if no buffer based sends are in queue and
+the maximum specified by 
+.Fa timetolive 
+bytes is in queue.
+.Pp
+The
+.Dv SCTP_PR_SCTP_RTX
+policy transforms the
+.Fa timetolive 
+into a number of retransmissions to allow.
+This policy
+always assures that at a minimum one send attempt is
+made of the data.
+After which no more than 
+.Fa timetolive
+retransmissions will be made before the data is skipped.
+.Pp
+.Fa stream_no
+is the SCTP stream that you wish to send the
+message on.
+Streams in SCTP are reliable (or partially reliable) flows of ordered
+messages.
+The 
+.Fa context
+field is used only in the event the message cannot be sent.
+This is an opaque
+value that the stack retains and will give to the user when a failed send
+is given if that notification is enabled (see
+.Xr sctp 4 ) .
+Normally a user process can use this value to index some application
+specific data structure when a send cannot be fulfilled.
+.Sh RETURN VALUES
+.Rv -std sctp_sendmsg
+.Sh ERRORS
+The
+.Nm
+system call
+fail if:
+.Bl -tag -width ".Er EHOSTUNREACH"
+.It Bq Er EBADF
+An invalid descriptor was specified.
+.It Bq Er ENOTSOCK
+The argument
+.Fa s
+is not a socket.
+.It Bq Er EFAULT
+An invalid user space address was specified for an argument.
+.It Bq Er EMSGSIZE
+The socket requires that message be sent atomically,
+and the size of the message to be sent made this impossible.
+.It Bq Er EAGAIN
+The socket is marked non-blocking and the requested operation
+would block.
+.It Bq Er ENOBUFS
+The system was unable to allocate an internal buffer.
+The operation may succeed when buffers become available.
+.It Bq Er ENOBUFS
+The output queue for a network interface was full.
+This generally indicates that the interface has stopped sending,
+but may be caused by transient congestion.
+.It Bq Er EHOSTUNREACH
+The remote host was unreachable.
+.It Bq Er ENOTCON
+On a one to one style socket no association exists.
+.It Bq Er ECONNRESET
+An abort was received by the stack while the user was
+attempting to send data to the peer.
+.It Bq Er ENOENT
+On a one to many style socket no address is specified
+so that the association cannot be located or the
+.Dv SCTP_ABORT
+flag was specified on a non-existing association.
+.It Bq Er EPIPE
+The socket is unable to send anymore data
+.Pf ( Dv SBS_CANTSENDMORE
+has been set on the socket).
+This typically means that the socket
+is not connected and is a one-to-one style socket.
+.El
+.Sh SEE ALSO
+.Xr getsockopt 2 ,
+.Xr recv 2 ,
+.Xr select 2 ,
+.Xr sendmsg 2 ,
+.Xr socket 2 ,
+.Xr write 2
+.Sh BUGS
+Because
+.Nm
+may have multiple associations under one endpoint, a
+select on write will only work for a one-to-one style
+socket.
