z/OS Communications Server: IP Sockets Application Programming Interface Guide and Reference
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


sendmsg()

z/OS Communications Server: IP Sockets Application Programming Interface Guide and Reference
SC27-3660-00

The sendmsg() call sends messages on a socket with descriptor s passed in an array of message headers.

#include <manifest.h>
#include <bsdtypes.h>
#include <socket.h>
 
int sendmsg(int s, struct msghdr *msg, int flags)
Parameter
Description
s
Socket descriptor.
msg
Points to an msghdr structure.
flags
Set the flags parameter by specifying one or more of the following flags. If more than one flag is specified, the logical OR operator (|) must be used to separate them. Setting this parameter is supported only for sockets in the AF_INET domain. Setting these flags is not supported in the AF_IUCV domain.
MSG_OOB
Sends out-of-band data on the socket.
MSG_DONTROUTE
The SO_DONTROUTE option is turned on for the duration of the operation; it is usually used by diagnostic or routing programs only.
A message header is defined by a msghdr. The definition of this structure can be found in the SOCKET.H header file and contains the following parameters.
Parameter
Description
msg_name
The pointer to the buffer containing the recipient address. This is required for datagram sockets where an explicit connect() has not been done.
msg_namelen
The size of the address buffer. This is required for datagram sockets where an explicit connect() has not been done.
msg_iov
An array of iovec buffers containing the message. The iovec buffer contains the following information:
iov_base
Points to the buffer.
iov_len
The length of the buffer.
msg_iovlen
The number of elements in the msg_iov array.
msg_accrights
The access rights sent. This field is ignored.
msg_accrightslen
The length of the access rights sent. This field is ignored.
The sendmsg() call applies to sockets regardless of whether they are in the connected state and returns the length of the data sent.

If there is not enough buffer space available to hold the socket data to be transmitted, and the socket is in blocking mode, sendmsg() blocks the caller until more buffer space becomes available. If the socket is in nonblocking mode, sendmsg() returns a -1 and sets errno to EWOULDBLOCK. See fcntl() or ioctl() to set nonblocking mode.

For datagram sockets, this call sends the entire datagram, providing the datagram can fit into the TCP/IP buffers. Stream sockets act like streams of information with no boundaries separating data. For example, if an application wants to send 1000 bytes, each call to this function can send 1 byte, or 10 bytes, or the entire 1000 bytes. Therefore, applications using stream sockets should place this call in a loop, and call this function until all data has been sent.

Return values

If successful, the length of the message in bytes is returned. The value -1 indicates an error. Errno identifies the specific error.
Errno
Description
EBADF
Indicates that s is not a valid socket descriptor.
EFAULT
Using msg would result in an attempt to access storage outside the caller address space.
EINVAL
Indicates that msg_namelen is not the size of a valid address for the specified address family.
EMSGSIZE
The message was too big to be sent as a single datagram.
ENOBUFS
Buffer space is not available to send the message.
EWOULDBLOCK
Indicates that s is in nonblocking mode and there is not enough space in TCP⁄IP to accept the data.

Related calls

connect(), fcntl(), getsockopt(), ioctl(), read(), readv(), recv(), recvfrom(), recvmsg(), select(), selectex(), send(), sendto(), setsockopt(), socket(), write(), writev()

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014