1send(3SOCKET)              Sockets Library Functions             send(3SOCKET)
2
3
4

NAME

6       send, sendto, sendmsg - send a message from a socket
7

SYNOPSIS

9       cc [ flag... ] file... -lsocket  -lnsl  [ library... ]
10       #include <sys/types.h>
11       #include <sys/socket.h>
12
13       ssize_t send(int s, const void *msg, size_t len, int flags);
14
15
16       ssize_t sendto(int s, const void *msg, size_t len, int flags,
17            const struct sockaddr *to, int  tolen);
18
19
20       ssize_t sendmsg(int s, const struct msghdr *msg, int flags);
21
22

DESCRIPTION

24       The  send(),  sendto(),  and sendmsg() functions are used to transmit a
25       message to another transport end-point. The send() function can be used
26       only when the socket is in a connected state. See connect(3SOCKET). The
27       sendto() and sendmsg() functions can be used at any time. The s  socket
28       is created with socket(3SOCKET).
29
30
31       The address of the target is supplied by to with a tolen parameter used
32       to specify the size. The length of the message is supplied by  the  len
33       parameter.  For  socket  types  such  as  SOCK_DGRAM  and SOCK_RAW that
34       require atomic messages, the error EMSGSIZE is returned and the message
35       is  not  transmitted when it is too long to pass atomically through the
36       underlying protocol. The same restrictions do not apply to  SOCK_STREAM
37       sockets.
38
39
40       A  return value −1 indicates locally detected errors. It does not imply
41       a delivery failure.
42
43
44       If the socket does not have enough buffer space  available  to  hold  a
45       message,  the send() function blocks the message, unless the socket has
46       been placed in non-blocking I/O mode (see fcntl(2)). The select(3C)  or
47       poll(2)  call can be used to determine when it is possible to send more
48       data.
49
50
51       The flags parameter is formed from the bitwise OR of zero  or  more  of
52       the following:
53
54       MSG_OOB          Send  out-of-band  data  on  sockets that support this
55                        notion. The underlying protocol must also support out-
56                        of-band  data. Only SOCK_STREAM sockets created in the
57                        AF_INET or the AF_INET6 address family support out-of-
58                        band data.
59
60
61       MSG_DONTROUTE    The  SO_DONTROUTE option is turned on for the duration
62                        of the operation. It is used  only  by  diagnostic  or
63                        routing programs.
64
65
66
67       See recv(3SOCKET) for a description of the msghdr structure.
68

RETURN VALUES

70       Upon  successful completion, these functions return the number of bytes
71       sent. Otherwise, they return -1 and set errno to indicate the error.
72

ERRORS

74       The send(), sendto(), and sendmsg() functions return errors  under  the
75       following conditions:
76
77       EBADF           s is not a valid file descriptor.
78
79
80       EINTR           The  operation  was interrupted by delivery of a signal
81                       before any data could be buffered to be sent.
82
83
84       EMSGSIZE        The message is too large to be sent all at once (as the
85                       socket  requires),  or  the  msg_iovlen  member  of the
86                       msghdr structure pointed to by message is less than  or
87                       equal to 0 or is greater than {IOV_MAX}.
88
89
90       ENOMEM          Insufficient memory is available to complete the opera‐
91                       tion.
92
93
94       ENOSR           Insufficient STREAMS resources are  available  for  the
95                       operation to complete.
96
97
98       ENOTSOCK        s is not a socket.
99
100
101       EWOULDBLOCK     The  socket  is  marked  non-blocking and the requested
102                       operation would block.  EWOULDBLOCK  is  also  returned
103                       when  sufficient memory is not immediately available to
104                       allocate a suitable buffer. In such a case, the  opera‐
105                       tion can be retried later.
106
107
108       ECONNREFUSED    The  requested  connection was refused by the peer. For
109                       conected IPv4 and IPv6 datagram sockets, this indicates
110                       that  the  system  received  an  ICMP  Destination Port
111                       Unreachable message from the peer in response  to  some
112                       prior transmission.
113
114
115
116       The  send()  and  sendto()  functions return errors under the following
117       conditions:
118
119       EINVAL    The len argument overflows a ssize_t.
120
121                 Inconsistent port attributes for system call.
122
123
124
125       The sendto() function returns errors under the following conditions:
126
127       EINVAL    The value specified for the tolen parameter is not  the  size
128                 of a valid address for the specified address family.
129
130
131       EISCON    A destination address was specified and the socket is already
132                 connected.
133
134
135
136       The sendmsg() function returns errors under the following conditions:
137
138       EINVAL    The msg_iovlen member of the msghdr structure pointed  to  by
139                 msg  is  less  than  or equal to 0, or the sum of the iov_len
140                 values in the msg_iov array overflows a ssize_t.
141
142                 One of the iov_len values in the msg_iov array member of  the
143                 msghdr structure pointed to by msg is negative, or the sum of
144                 the iov_len values in the msg_iov array overflows a ssize_t.
145
146                 msg_iov contents are inconsistent with port attributes.
147
148
149
150       The send() function returns errors under the following conditions:
151
152       EPIPE    The socket is shut down for writing, or the socket is  connec‐
153                tion-mode  and  is no longer connected. In the latter case, if
154                the socket is of type SOCK_STREAM, the SIGPIPE signal is  gen‐
155                erated to the calling thread.
156
157

ATTRIBUTES

159       See attributes(5) for descriptions of the following attributes:
160
161
162
163
164       ┌─────────────────────────────┬─────────────────────────────┐
165       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
166       ├─────────────────────────────┼─────────────────────────────┤
167       │Interface Stability          │Committed                    │
168       ├─────────────────────────────┼─────────────────────────────┤
169       │MT-Level                     │Safe                         │
170       └─────────────────────────────┴─────────────────────────────┘
171

SEE ALSO

173       fcntl(2),  poll(2),  write(2),  connect(3SOCKET),  getsockopt(3SOCKET),
174       recv(3SOCKET),    select(3C),     socket(3SOCKET),     socket.h(3HEAD),
175       attributes(5)
176
177
178
179SunOS 5.11                        31 Aug 2009                    send(3SOCKET)
Impressum