gtpc1m4bTransmission Control Protocol/Internet Protocol

sendmsg -- Send Message on a Socket

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

Format

#include  <socket.h>
int       sendmsg(int s,
                  struct msghdr *msg,
                  int flags);

s
The socket descriptor.

msg
A pointer to the message header that receives the messages.

flags
Must be set to 0 or one or more of the following flags. If you specify more than one flag, use the logical OR operator (|) to separate them:

MSG_OOB
Reads any out-of-band data on the socket.

MSG_DONTROUTE
The SO_DONTROUTE option is turned on for the duration of the operation. This is mainly used by diagnostic or routing programs.
Note:
Setting this parameter is supported for sockets in the AF_INET domain, but not supported for sockets in the AF_IUCV domain.

Normal Return

If successful, the function returns the length of the data sent.

Error Return

A return code equal to -1 indicates an error. You can get the specific error code by calling sock_errno. See Appendix C, Socket Error Return Codes for more information about socket errors.

Note:
The following error codes can be returned for either TCP/IP offload support or TCP/IP native stack support.

Value
Description

EINVAL
msg_namelen is not the size of a valid address for the specified address family.

EMSGSIZE
Either the message is too big to be sent as a single datagram or the iovector count is greater than or equal to UIO_MAXIOV as defined in socket.h.

ENOBUFFS
Buffer space is not available to send the message.

ENOMEM
There is no memory allocating buffer space to hold all messages in the iovec array.

EWOULDBLOCK
The s parameter is in nonblocking mode and data cannot be sent.

SOCBADF
The s parameter is not a valid socket descriptor.

SOCFAULT
Using msg would result in an attempt to access memory the address space of the caller.

SOCNOTSOCK
The s parameter is not a valid socket descriptor.

Programming Considerations

Examples

In the following example, the application issues a sendmsg function to send messages on a socket.

#include <socket.h>
struct msghdr         msg;
int                   sock;   /* UNIX socket handle                      */
rpc_socket_iovec_p_t  iovp;   /* array of bufs of data to send           */
int                   iovlen; /* number of bufs                          */
rpc_addr_p_t          addrp;  /* address of sender                       */
int                   *ccp;   /* returned number of bytes actually sent  */

·
·
·
msg.msg_name = (caddr_t) &(addrp)->sa: msg.msg_namelen = (addrp)->len; msg.msg_iov = (struct iovec *) iovp; msg.msg_iovlen = iovlen; msg.msg_accrights = NULL; msg.msg_accrightslen = 0; *(ccp) = sendmsg ((int) sock, (struct msghdr *) &msg, 0);

Related Information