[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Communications, Volume 2

sendmsg Subroutine


Sends a message from a socket using a message structure.


Standard C Library (libc.a)


#include <sys/types.h>
#include <sys/socketvar.h>
#include <sys/socket.h>

int sendmsg ( Socket, Message, Flags)
int Socket;
const struct msghdr Message [ ];
int Flags;


The sendmsg subroutine sends messages through connected or unconnected sockets using the msghdr message structure. The /usr/include/sys/socket.h file contains the msghdr structure and defines the structure members. In BSD 4.4, the size and members of the msghdr message structure have been modified. Applications wanting to start the old structure need to compile with COMPAT_43 defined. The default behaviour is that of BSD 4.4.

To broadcast on a socket, the application program must first issue a setsockopt subroutine using the SO_BROADCAST option to gain broadcast permissions.

The sendmsg subroutine supports only 15 message elements.

All applications containing the sendmsg subroutine must be compiled with _BSD set to a specific value. Acceptable values are 43 and 44. In addition, all socket applications must include the BSD libbsd.a library.


Socket Specifies the socket descriptor.
Message Points to the msghdr message structure containing the message to be sent.
Flags Allows the sender to control the message transmission. The sys/socket.h file contains the Flags parameter. The Flags parameter used to send a call is formed by logically ORing one or both of the following values:
Processes out-of-band data on sockets that support SOCK_STREAM.
The following value is not for general use. It is an administrative tool used for debugging or for routing programs.
Sends without using routing tables.
Indicates that this block is a MPEG2 block. It only applies to SOCK_CONN_DGRAM types of sockets only.

Return Values

Upon successful completion, the sendmsg subroutine returns the number of characters sent.

If the sendmsg subroutine is unsuccessful, the system handler performs the following functions:

Error Codes

The sendmsg subroutine is unsuccessful if any of the following errors occurs:

Error Description
EBADF The Socket parameter is not valid.
ENOTSOCK The Socket parameter refers to a file, not a socket.
EWOULDBLOCK The socket is marked nonblocking, and no connections are present to be accepted.

Related Information

The no command.

The connect subroutine, getsockopt subroutine, recv subroutine, recvfrom subroutine, recvmsg subroutine, select subroutine, send subroutine, sendto subroutine, setsockopt subroutine. shutdown subroutine, socket subroutine.

Sockets Overview and Understanding Socket Data Transfer in AIX 5L Version 5.2 Communications Programming Concepts.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]