1SENDMSG(P)                 POSIX Programmer's Manual                SENDMSG(P)
2
3
4

NAME

6       sendmsg - send a message on a socket using a message structure
7

SYNOPSIS

9       #include <sys/socket.h>
10
11       ssize_t sendmsg(int socket, const struct msghdr *message, int flags);
12
13

DESCRIPTION

15       The  sendmsg()  function shall send a message through a connection-mode
16       or connectionless-mode socket. If the  socket  is  connectionless-mode,
17       the  message  shall  be sent to the address specified by msghdr. If the
18       socket is connection-mode, the destination address in msghdr  shall  be
19       ignored.
20
21       The sendmsg() function takes the following arguments:
22
23       socket Specifies the socket file descriptor.
24
25       message
26              Points  to  a  msghdr structure, containing both the destination
27              address and the buffers for the outgoing message. The length and
28              format  of  the  address  depend  on  the  address family of the
29              socket. The msg_flags member is ignored.
30
31       flags  Specifies the type of message transmission. The application  may
32              specify 0 or the following flag:
33
34       MSG_EOR
35              Terminates a record (if supported by the protocol).
36
37       MSG_OOB
38              Sends  out-of-band  data  on  sockets  that support out-of-bound
39              data.  The significance and semantics of  out-of-band  data  are
40              protocol-specific.
41
42
43
44       The  msg_iov and msg_iovlen fields of message specify zero or more buf‐
45       fers containing the data to be sent.  msg_iov points  to  an  array  of
46       iovec  structures;  msg_iovlen  shall  be  set to the dimension of this
47       array. In each iovec structure, the iov_base field specifies a  storage
48       area and the iov_len field gives its size in bytes. Some of these sizes
49       can be zero. The data from each storage area indicated  by  msg_iov  is
50       sent in turn.
51
52       Successful  completion of a call to sendmsg() does not guarantee deliv‐
53       ery of the message. A  return  value  of  -1  indicates  only  locally-
54       detected errors.
55
56       If  space is not available at the sending socket to hold the message to
57       be transmitted and the socket file descriptor does not have  O_NONBLOCK
58       set,  the  sendmsg()  function shall block until space is available. If
59       space is not available at the sending socket to hold the message to  be
60       transmitted  and  the  socket file descriptor does have O_NONBLOCK set,
61       the sendmsg() function shall fail.
62
63       If the socket protocol supports broadcast and the specified address  is
64       a  broadcast  address  for the socket protocol, sendmsg() shall fail if
65       the SO_BROADCAST option is not set for the socket.
66
67       The socket in use may require the process to  have  appropriate  privi‐
68       leges to use the sendmsg() function.
69

RETURN VALUE

71       Upon  successful completion, sendmsg() shall return the number of bytes
72       sent. Otherwise, -1 shall be returned and errno  set  to  indicate  the
73       error.
74

ERRORS

76       The sendmsg() function shall fail if:
77
78       EAGAIN or EWOULDBLOCK
79              The  socket's  file  descriptor  is  marked  O_NONBLOCK  and the
80              requested operation would block.
81
82       EAFNOSUPPORT
83              Addresses in the specified address family cannot  be  used  with
84              this socket.
85
86       EBADF  The socket argument is not a valid file descriptor.
87
88       ECONNRESET
89              A connection was forcibly closed by a peer.
90
91       EINTR  A signal interrupted sendmsg() before any data was transmitted.
92
93       EINVAL The sum of the iov_len values overflows an ssize_t.
94
95       EMSGSIZE
96              The  message  is too large to be sent all at once (as the socket
97              requires), or the msg_iovlen  member  of  the  msghdr  structure
98              pointed  to  by message is less than or equal to 0 or is greater
99              than {IOV_MAX}.
100
101       ENOTCONN
102              The socket is connection-mode but is not connected.
103
104       ENOTSOCK
105              The socket argument does not refer to a socket.
106
107       EOPNOTSUPP
108              The socket argument is associated with a socket  that  does  not
109              support one or more of the values set in flags.
110
111       EPIPE  The  socket  is  shut down for writing, or the socket is connec‐
112              tion-mode and is no longer connected. In the latter case, and if
113              the  socket is of type SOCK_STREAM, the SIGPIPE signal is gener‐
114              ated to the calling thread.
115
116
117       If the address family of the socket is AF_UNIX,  then  sendmsg()  shall
118       fail if:
119
120       EIO    An  I/O error occurred while reading from or writing to the file
121              system.
122
123       ELOOP  A loop exists in symbolic links encountered during resolution of
124              the pathname in the socket address.
125
126       ENAMETOOLONG
127              A  component of a pathname exceeded {NAME_MAX} characters, or an
128              entire pathname exceeded {PATH_MAX} characters.
129
130       ENOENT A component of the pathname does not name an  existing  file  or
131              the path name is an empty string.
132
133       ENOTDIR
134              A  component  of  the  path prefix of the pathname in the socket
135              address is not a directory.
136
137
138       The sendmsg() function may fail if:
139
140       EACCES Search permission is denied for a component of the path  prefix;
141              or write access to the named socket is denied.
142
143       EDESTADDRREQ
144              The  socket  is  not  connection-mode and does not have its peer
145              address set, and no destination address was specified.
146
147       EHOSTUNREACH
148              The destination host cannot be  reached  (probably  because  the
149              host is down or a remote router cannot reach it).
150
151       EIO    An  I/O error occurred while reading from or writing to the file
152              system.
153
154       EISCONN
155              A destination address was specified and the  socket  is  already
156              connected.
157
158       ENETDOWN
159              The  local  network  interface  used to reach the destination is
160              down.
161
162       ENETUNREACH
163              No route to the network is present.
164
165       ENOBUFS
166              Insufficient resources were available in the system  to  perform
167              the operation.
168
169       ENOMEM Insufficient memory was available to fulfill the request.
170
171
172       If the address family of the socket is AF_UNIX, then sendmsg() may fail
173       if:
174
175       ELOOP  More than {SYMLOOP_MAX} symbolic links were  encountered  during
176              resolution of the pathname in the socket address.
177
178       ENAMETOOLONG
179              Pathname  resolution of a symbolic link produced an intermediate
180              result whose length exceeds {PATH_MAX}.
181
182
183       The following sections are informative.
184

EXAMPLES

186       Done.
187

APPLICATION USAGE

189       The select() and poll() functions can be used to determine when  it  is
190       possible to send more data.
191

RATIONALE

193       None.
194

FUTURE DIRECTIONS

196       None.
197

SEE ALSO

199       getsockopt()  ,  poll()  , recv() , recvfrom() , recvmsg() , select() ,
200       send() , sendto() , setsockopt() , shutdown() ,  socket()  ,  the  Base
201       Definitions volume of IEEE Std 1003.1-2001, <sys/socket.h>
202
204       Portions  of  this text are reprinted and reproduced in electronic form
205       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
206       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
207       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
208       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
209       event of any discrepancy between this version and the original IEEE and
210       The  Open Group Standard, the original IEEE and The Open Group Standard
211       is the referee document. The original Standard can be  obtained  online
212       at http://www.opengroup.org/unix/online.html .
213
214
215
216IEEE/The Open Group                  2003                           SENDMSG(P)
Impressum